Skip to content
Advertisement

Insert only few columns from exec (SQL) when column name is not fixed

I have the below code:

The output is:

The output is

I know that EXEC(SQL) will give me 12 columns, so i created the temporary table #Tbl_Eval_Temp with 12 columns. What if the number of columns and the name of the columns is also getting generated at run time. There could be only 5 or 15 columns. So, how can I still achieve the desired output as shown in the pic?

Advertisement

Answer

You can use exec sp_executesql like this code that I coded it for you :

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement