|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, May 17, 2010 8:40 AM
Points: 6,
Visits: 41
|
|
hi, i'm trying to dynamically create a tablename in tsql so that the tablename contains the month and year. I keep getting an error that the stored procedure cannot be executed. can someone please tell me where i'm going wrong?
thanks!
declare @strsqlcreatetable as nvarchar(255) declare @tablename as nvarchar(255) declare @strsql as nvarchar(255)
select @tablename = 'lclifecycle' + convert(nvarchar(2), datepart(mm, getdate())) + convert(nvarchar(4), datepart(yyyy, getdate())) print @tablename
select @strsqlcreatetable = 'create table ' + @tablename + '(emp int)' print @strsqlcreatetable exec @strsqlcreatetable
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 1:48 AM
Points: 1,252,
Visits: 3,367
|
|
declare @strsqlcreatetable as nvarchar(255) declare @tablename as nvarchar(255) declare @strsql as nvarchar(255)
select @tablename = 'lclifecycle' + convert(nvarchar(2), datepart(mm, getdate())) + convert(nvarchar(4), datepart(yyyy, getdate())) print @tablename
select @strsqlcreatetable = 'create table ' + @tablename + '(emp int)' print @strsqlcreatetable exec (@strsqlcreatetable) --there is your missing parenthesis!
============================================================ SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION = http://www.sqlservercentral.com/articles/Best+Practices/61537/
|
|
|
|