September 29, 2006 at 4:38 am
I want to create dynamic tables, I am using the follwing script but it gives me error
declare @tablename varchar (100)
set @tablename = '#BackupFile_' + replace(replace(cast(getdate() as varchar),' ',''),':','')
select @tablename
create table @tablename
(
[name] [nvarchar] (100)
)
error :
Incorrect syntax near '@tablename'.
September 29, 2006 at 4:50 am
Try this.
declare @tablename varchar (100)
set @tablename = '#BackupFile_' + replace(replace(cast(getdate() as varchar),' ',''),':','')
select @tablename
EXEC ('CREATE TABLE '+@tablename+ '([name] [nvarchar] (100))')
Ram
September 29, 2006 at 6:47 am
I would just use the convert function, something like:
set
@tablename = '#BackupFile_' + convert(varchar, getdate(), 112)
Which gives values such as, #BackupFile_20060929
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply