How to store the result in Temp Table from EXEC command ?
I have following scenario- Declare @Sql varchar(1024) = 'Select * from dbo.Employee' Exec (@Sql) The above example is giving me result in Sql Server result pane. but i want to store the result in Temprory Table. How to do that ? Please reply if any one know
Matt's right above, but if you aren't forced to use an EXEC and only want a SELECT statement's results into a temp table, you can also use the format: SELECT * INTO #myTable FROM dbo.Employee One drawback to this method is that you can't control the temp table's structure that way. The column types, widths, etc. are determined by the table(s) you are selecting them from.