I am attempting to write code that drops tables/databases based on a date. I have several databases/tables with the following names:
Database - XXX_122006
tables - PT_122006
PD_122006
Database - XXX_012007
tables - PT_012007
PD_012007
I have the following code:
declare @ldProcDate smalldatetime
declare @lcProcDate char(10)
declare @lcDB char(17)
set @ldProcDate = '01-01-2007 00:00:00'
set @lcProcDate = convert(char, @ldProcDate, 103)
set @lcDB = 'XXX_' + substring(@lcProcDate, 4, 2) + substring(@lcProcDate, 7, 4) + '.Dbo.PT'
IF OBJECT_ID(@lcDB, 'U') is not null
drop table @lcDB
When I run this code I receive a general syntax error. In other languages one would place an '&' in front of the @lcDB to pass the variable by reference. How would this be accomplished in TSQL?
Database - XXX_122006
tables - PT_122006
PD_122006
Database - XXX_012007
tables - PT_012007
PD_012007
I have the following code:
declare @ldProcDate smalldatetime
declare @lcProcDate char(10)
declare @lcDB char(17)
set @ldProcDate = '01-01-2007 00:00:00'
set @lcProcDate = convert(char, @ldProcDate, 103)
set @lcDB = 'XXX_' + substring(@lcProcDate, 4, 2) + substring(@lcProcDate, 7, 4) + '.Dbo.PT'
IF OBJECT_ID(@lcDB, 'U') is not null
drop table @lcDB
When I run this code I receive a general syntax error. In other languages one would place an '&' in front of the @lcDB to pass the variable by reference. How would this be accomplished in TSQL?