[thelist] (sql2k) syntax error in sproc -- now a run-time error
Tab Alleman
Tab.Alleman at MetroGuide.com
Wed Jul 9 14:08:40 CDT 2003
It turns out that the problem was that I hadn't yet written a statement
to be carried out if the IF condition was met. I didn't think the
syntax checker would catch that: I figured it would be a run-time
error.
So anyway, I got my sproc past the syntax-check, but now I'm getting a
run-time error. The two pertinent bits of code are:
...
SET @ThisYear = Year(DATEADD(dy, -60, GetDate()))
SET @Database = 'dw_tab'
SET @ArchiveTableName = 'ea' + @ThisYear
...
And
...
CREATE TABLE [@Database].[dbo].[@ArchiveTableName] (
...
The error occurs on the CREATE TABLE line, saying:
Server: Msg 2702, Level 16, State 2, Procedure tsp_ArchiveSentEmail,
Line 21
Database '@Database' does not exist.
What should I do differently to get it to use the value of @Database (in
this case, 'dw_tab') in the CREATE TABLE query?
More information about the thelist
mailing list