Suelowe
asked on
Using a variable to reference a table name in T-SQL and accessing the resultant temporary table.
I have constructed a string of dynamic SQL which concatenates a select statement with a variable containing the name of the table I wish to interrogate. This works fine and I can see the results clearly. My problem is that I need to store the results of my query in a temporary table (which I've called #temp1) in order to further manipulate the data; the 'select into' statement works fine, but the following query is failing with the message 'Invalid object name #temp1'. Does anybody have a solution which would enable me to access the temporary table please? Perhaps an alternative way of declaring/setting/using a variable as a table name?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER