Link to home
Start Free TrialLog in
Avatar of donpick
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?
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image



SET @callEXEC = 'exec spB  ' + ''' + @itemID + '',' + CAST(@intActive AS varchar(1))


EXEC @callEXEC

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial