Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 syntax for passing variable-usp

Author  Topic 

Champinco
Yak Posting Veteran

54 Posts

Posted - 2007-05-20 : 22:06:27
hi guys what is the syntax for using the passing variable part into the name of a table in a store procedure. in particular: (assume already declared the variable periodseq.


select *
into Temp_Usage_@periodseq
from Master_usage
where Master_usage.PERIODSEQ = @periodseq


in particular the Temp_Usage_@periodseq line of code, how do i "add" the periodseq (which is a number) to the end of the name of Temp_Usage, i.e: Temp_Usage_112
is the syntax an & like Temp_Usage_&@periodseq?
Cheers
Champinco

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-20 : 22:10:53
You can't do that. You will have to resort to dynamic sql like exec() or sp_executesql.

Take a look at http://www.sommarskog.se/dynamic_sql.html


KH

Go to Top of Page
   

- Advertisement -