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 |
|
johnyan
Starting Member
4 Posts |
Posted - 2007-05-11 : 07:21:22
|
| Hi all, I am creating the below Stored Procedure in that i m passing table name as a argument i have decalred @TableName also,but when i run it is giving me error message 'Must declare table variable @TableName. whre i m going wrong can u please tell me..or is there any other way.CREATE Procedure AddNewUser1( @Name nvarchar(25), @LoginID nvarchar(25), @Password nvarchar(16), @DOB nvarchar (8), @Gender nvarchar (8), @Country nvarchar(50), @TableName nvarchar(25), @UserID smallint OUTPUT )ASSelect * From Users Where LoginID=@LoginID If @@rowcount=0 Begin Insert Into @TableName (LoginID,Password,Name,DOB,Gender,Country) values(@LoginID,@Password,@Name,@DOB,@Gender,@Country) select @UserID=1 Endelse select @UserID=-1GO |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-11 : 07:23:09
|
| You need dynamic sql here. But frankly this is not a good design. Why you need to pass table name as parameter?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
johnyan
Starting Member
4 Posts |
Posted - 2007-05-11 : 07:37:31
|
| Hi thanks for your reply.I m creating my table on rum time as a session tabel. and in each request of my page it should create a new session tabel.thare for i m passing my table name as a argument.it there any way to solve this problem. bcoz my table name should be dynamic.Thanks-john |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-11 : 07:54:17
|
| it seems ur in urgent...Exec('Insert Into ' + @TableName + ' (LoginID,Password,Name,DOB,Gender,Country)values('+ @LoginID + ',' + @Password + ',' + @Name + ',' + @DOB + ',' + @Gender + ',' + @Country+')') |
 |
|
|
|
|
|
|
|