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.
| Author |
Topic |
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2011-08-26 : 09:14:36
|
| Hi All,I am trying to execute this query.sp_rename 'Emp','Employee' + CAST(GETDATE() as nvarchar(max))Msg 102, Level 15, State 1, Line 1Incorrect syntax near '+'. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-26 : 09:30:23
|
first store expression in a variable and then use itDECLARE @TableName varchar(100)SET @TableName='Employee' + CAST(GETDATE() as nvarchar(max))sp_rename 'Emp',@TableName ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2011-08-26 : 09:33:18
|
| getting error Msg 102, Level 15, State 1, Line 3Incorrect syntax near 'sp_rename'. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-26 : 09:43:33
|
| [code]DECLARE @TableName varchar(100)SET @TableName='Employee' + CAST(GETDATE() as nvarchar(max))EXEC sp_rename 'Emp',@TableName[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-08-29 : 03:45:44
|
| Why are you appending current date as part of table name? Are you creating tables dynamically?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|