Can I create a table using a variable for the table_name?? I need to run multiple versions of a stored proc simultaneously each if which creates tables to store data temporarily. So I need to generate a different table name for each version based on the input parameter for that version of the stored proc.
Appreciate your help on this.
Thanks to Michael, I ve been using the exec (@cmd) format with great success for create, 'select into ', insert stmts, within the stored proc. BUt now I've hit another challenge ....I need to read the rowcount of one of the tables into a variable...let me explain:
- I create a table using this cmd:
select @cmd = "select * into " + @name + " from table_name where 1=2 "
- Similarly I insert rows.
- Now I need to read the rowcount of the table into a variable. i.e.:
select @cnt = count(*) from @name where col1 = @abc