donpick
asked on
EXEC statement - how to put quotes around a string variable
Running SQL SERVER 2000 on SBS 2003 Premium
My question:
I am trying to construct an EXEC statement.
Lets say there are 2 sproc's: spA and spB.
spA:
DECLARE @itemID varchar(30)
DECLARE @intActive tinyint
DECLARE @callEXEC varchar(200)
@intActive = 1
SELECT @itemID = MAX(tblStores.itemID)
FROM tblStores
WHERE tblStores.Active = @intActive
SET @callEXEC = 'spB ' + ''' + @itemID + ''' + CAST(@intActive AS varchar(1))
EXEC @callEXEC
spB
DECLARE @itemID2
DECLARE @strActive
My question: I do not seem to know how to put quotes around @itemID. When I execute this SQL tells me:
>> Cannot find spB VVZ 1
Please note: VVZ is one of the itemID's.
Suggestions?
My question:
I am trying to construct an EXEC statement.
Lets say there are 2 sproc's: spA and spB.
spA:
DECLARE @itemID varchar(30)
DECLARE @intActive tinyint
DECLARE @callEXEC varchar(200)
@intActive = 1
SELECT @itemID = MAX(tblStores.itemID)
FROM tblStores
WHERE tblStores.Active = @intActive
SET @callEXEC = 'spB ' + ''' + @itemID + ''' + CAST(@intActive AS varchar(1))
EXEC @callEXEC
spB
DECLARE @itemID2
DECLARE @strActive
My question: I do not seem to know how to put quotes around @itemID. When I execute this SQL tells me:
>> Cannot find spB VVZ 1
Please note: VVZ is one of the itemID's.
Suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SET @callEXEC = 'exec spB ' + ''' + @itemID + '',' + CAST(@intActive AS varchar(1))
EXEC @callEXEC