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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-02-12 : 10:58:42
|
| Hi,What is wrong with this please?alter table @tbltestadd lastname varchar(200) nullError is:incorrect syntax near @tbltestThanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 11:02:03
|
| you cant use variable like this. for that you need dynamic sqlEXEC('alter table '+ @tbltest + 'add lastname varchar(200) null')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-02-12 : 11:06:47
|
quote: Originally posted by visakh16 you cant use variable like this. for that you need dynamic sqlEXEC('alter table '+ @tbltest + 'add lastname varchar(200) null')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
It throws the errorMsg 137, Level 15, State 2, Line 2Must declare the scalar variable "@tbltest".Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 11:09:08
|
quote: Originally posted by senthil_nagore
quote: Originally posted by visakh16 you cant use variable like this. for that you need dynamic sqlEXEC('alter table '+ @tbltest + 'add lastname varchar(200) null')------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
It throws the errorMsg 137, Level 15, State 2, Line 2Must declare the scalar variable "@tbltest".Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
you need to declare it before using. I assumed OP have done that or else OP might have got same error------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-02-12 : 11:59:15
|
| thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 12:07:44
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|