Gossamer Forum
Home : General : Databases and SQL :

Problem using varaibles in Stored Procedure

Quote Reply
Problem using varaibles in Stored Procedure
Hi,

I have a problem creating Stored Procedure in MS SQL

I am using a variable which is not understood by the query. My code is as below.

CREATE PROCEDURE [Get_Test]
@iUserID varchar(10),
@sUsername varchar(50) output
AS
Declare @sSql nvarchar(2000), @User varchar(50)
Declare @sColumn varchar(20)
Declare @sTable varchar(50), @sReturnColumn varchar(20)

SET @sColumn = "mem_id"
SET @sTable = "members"
SET @sReturnColumn = "mem_username"

SELECT @User = @sReturnColumn FROM @sTable WHERE @sColumn = @iUserID
GO


I get an Error 137: Must declare variable @sTable. Can anybody help me out in this. Thanks to anyone who responds.

Bhavesh
Subject Author Views Date
Thread Problem using varaibles in Stored Procedure bhavesh 3347 Sep 11, 2002, 6:40 AM
Post Re: [bhavesh] Problem using varaibles in Stored Procedure
dregs2 3162 Sep 16, 2002, 11:43 AM