Solved

EXEC statement - how to put quotes around a string variable

Posted on 2007-03-24
2
479 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:donpick
2 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18787430


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


EXEC @callEXEC

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18787828
corrections:
* you need brackets when calling SQL text with EXEC
* you need to put the single quotes doubled

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

EXEC (@callEXEC)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now