Solved

EXEC statement - how to put quotes around a string variable

Posted on 2007-03-24
2
480 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help on t-sql 2012 10 54
get column names from table in vb.net 8 28
Help in Bulk Insert 9 33
SQL Server 2015 Restore - doing it right 2 8
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

770 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