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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Variable to table name

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-20 : 09:58:58
Tim writes "I have a set of Archives and want to pass a variable to the name of a table How can I make this work

as in we are in month 4 so it makes
Archive_pagelog_4

hereis what i have so far

CREATE PROCEDURE ArchivePageLog
(
@Job_id int,
@month char(2)
)
AS
SET NOCOUNT ON
BEGIN TRANSACTION

INSERT INTO Archive_pagelog_ + @month SELECT * FROM pagelog WHERE Job_id = @job_id"

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-04-20 : 10:49:40
EXEC ('INSERT INTO Archive_pagelog_' + @month + ' SELECT * FROM pagelog WHERE Job_id = ' + LTRIM(STR(@job_id, 8))


Duane.
Go to Top of Page
   

- Advertisement -