Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
joshhansen29
Frequent Visitor

Create SQL query from string in multiple rows.

Hello All,

 

I realize that this might not be the best approach to doing this, but I was hoping to see if it's possible.

Overall Objective: I'm trying to use power query to generate a list of all columns and data types from every Stored Procedure in a database.

Stored Procedurenamesystem_type_name
DB_Sch.fmcParActionExecuteActionnvarchar(30)
DB_Sch.fmcParActionExecuteActionIdnvarchar(30)
DB_Sch.fmcParContainerIdContainerIdchar(16)
DB_Sch.fmcParContainerIdAssemblyContainerIdchar(16)
DB_Sch.fmcParDataCollectionDataCollectionIdchar(16)
DB_Sch.fmcParDataCollectionDataCollectionNamenvarchar(30)
DB_Sch.fmcParDataCollectionByTaskLlistDataCollectionDefNamenvarchar(30)
DB_Sch.fmcParDataCollectionRevDataCollectionDefBaseIdchar(16)
DB_Sch.fmcParDataCollectionRevDataCollectionnvarchar(48)

 

I've been able to get pretty close with a workaround, but it requires a manual step.

 

I have a query that generates a list of each stored procedure in the database. 

Stored Procedure
DB_Sch.fmcParAction
DB_Sch.fmcParContainerId
DB_Sch.fmcParContainerIdAssembly
DB_Sch.fmcParDataCollection
DB_Sch.fmcParDataCollectionByTaskLlist
DB_Sch.fmcParDataCollectionRev

 

I also have a query that will generate a list of each column from a single stored procedure. (The problem being that it will only return results for one stored procedure.)

 

SELECT 'DB_Sch.fmcParDataCollection' AS [SP], name, system_type_name

FROM sys.dm_exec_describe_first_result_set_for_object (OBJECT_ID('DB_Sch.fmcParDataCollection'), NULL) 

Stored Procedurenamesystem_type_name
DB_Sch.fmcParDataCollectionDataCollectionIdchar(16)
DB_Sch.fmcParDataCollectionDataCollectionNamenvarchar(30)

 

So my current solution is to use the first query to generate the list of stored procedures, then add an additional column that creates the query for each Stored Procedure with a UNION at the end of each row.

image.png

 

At this point, I can copy the text from the Query column and paste it in as the SQL statement that will generate what I'm looking for, but it is now a static query that will not bring in new Stored Procedures that are created without manually updating the query.

 

Thanks in advance!

Josh

2 REPLIES 2
dax
Community Support
Community Support

Hi joshhansen29, 

I am not clear about your requirement, if possible, could you please explain "I can copy the text from the Query column and paste it in as the SQL statement that will generate what I'm looking for, but it is now a static query that will not bring in new Stored Procedures that are created without manually updating the query." to me? Whether you could use query to get this value directly?

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

What I meant was that I can copy the entire column (Circled in red)

image.png

 

Then I can paste the text into the SQL Statement (Circled In blue) of the source of another query. 

 

image.png

 

I'm essentially using power query to write the text of another SQL query. I was just hoping that there is a way to do that directly without having to manually copy the generated text and paste it into the new query.

 

Does that make sense? 

Thanks!

Josh

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.