I have a temp table where I want to store the results of a stored procedure. To execute the stored procedure, I need to use variable values for the Database name, Database Server, and Stored Procedure name that are stored in a table. I need to work out how to write the SELECT * INTO using the OPENROWSET with my variables. This is what I have so far but there are syntax errors:
SELECT * INTO #tmpAccountsRetrieved
FROM OPENROWSET(@TempDbName, 'Server=' + @TempDbServer + ';Trusted_Connection=yes;', 'EXEC ' + @TempStoredProcName)
I'm pretty rusty on SQL so any help is much appreciated!