I have a messy stored procedure which uses dynamic sql.
I can debug it in runtime by adding print @sql;
where @sql;
is the string containing the dynamic SQL, right before I call execute (@sql);
.
Now, the multi-page stored procedure also creates dynamic tables and uses them in a query. I want to print those tables to the console right before I do an execute
, so that I know exactly what the query is trying to do.
However, the SQL Server 08 does not like that. When I try:
print #temp_table;
and try to compile the S.P. I get this error:
The name "#temp_table" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
Please help.
EDIT:
I am a noob when it comes to SQL. However, the following statement: select * from #tbl;
does not print anything to the console when it is run non-interactively; the print statement works though.
The following statement has incorrect syntax: print select * from #tbl;
. Is there a way for me to redirect the output of select to a file, if stdout is not an option?
Thanks.