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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with stored procedure...

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
)
AS
Select *
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
End
else
select @UserID=-1
GO

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 Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

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
Go to Top of Page

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+')')
Go to Top of Page
   

- Advertisement -