Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

EXEC statement - how to put quotes around a string variable

Posted on 2007-03-24
2
Medium Priority
?
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18787430


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


EXEC @callEXEC

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

704 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