Is there a way within a stored procedure to replace a table name in a select query with a variable containing that table name?
here is what I am trying to do
I get this errorCode:set @BackUpCtrl = 'BackLogTable' if ((select count(*) from @BackUpCtrl) = 0) or ((select count(*) from @BackUpCtrl) = 1000000) begin set @backUpNbr = 0 print '0' end
Msg 1087, Level 15, State 2, Procedure Test3, Line 71
Must declare the table variable "@BackUpCtrl".
I get the same error when I try to check if a table exists and then try to drop the table. SQL does not seem to like 'drop table @table'
It only works if i replace the @BackUpCtrl as the actual table names.Code:set @table = 'abcd' if exists(Select * from sysobjects where name = @table) drop table @table
I Looked into table variables, but I don't think it will help the case here because I wouldn't be able to use select into to duplicate the table variable as the BackLogTable before using the select queries.



Reply With Quote
Bookmarks