Sorry, messed up that last one.  If your data is varchar/string data,
then SQL will probably want apostrophes around it, so you'll need to
modify the [EMAIL PROTECTED] line to this (corrected) version:

Set @SQL = 'SELECT  usockId, usockCode, usockDesc, usockAmount
FROM   dbo.tbl_usocks
WHERE  usockDesc LIKE ''%HANDSET%'' 
AND usockCode  NOT IN (''' + replace(@usockList,',',''',''') + ''')
ORDER BY usockCode, usockDesc'

-----Original Message-----
From: Raster, Tim 
Sent: Wednesday, October 22, 2003 15:58
To: SQL
Subject: RE: SQL statement works but Stored Procedure fails?

That operation isn't allowed (at least not in MS SQL Server).  You have
basically build your SQL string, and then execute it.  Try something
like this:

CREATE PROCEDURE dbo.DCS_handsets_selected
AS
DECLARE @usockList varchar(2000), @SQL varchar(8000)

SELECT @usockList = usockCode
FROM tbl_dcs_handsets_selected
WHERE handsetid = 1

Set @SQL = 'SELECT  usockId, usockCode, usockDesc, usockAmount
FROM   dbo.tbl_usocks
WHERE  usockDesc LIKE ''%HANDSET%'' 
AND usockCode  NOT IN (' + @usockList + ')
ORDER BY usockCode, usockDesc'

Execute (@SQL)


/*
 or, if it's strings, you may have to do the same as above, except for
this line:

Set @SQL = 'SELECT  usockId, usockCode, usockDesc, usockAmount
FROM   dbo.tbl_usocks
WHERE  usockDesc LIKE ''%HANDSET%'' 
AND usockCode  NOT IN (''' + replace(@usockList,'''','''''') + ''')
ORDER BY usockCode, usockDesc'

*/



-----Original Message-----
From: Bosky, Dave [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 22, 2003 15:37
To: SQL
Subject: SQL statement works but Stored Procedure fails?

I have the following SQL statement that will return all items not in the
list.
It works fine as a simple sql statement but when I make a stored
procedure 
with the query it doesn't return the expected results.
This list has been extremely helpful so I thought I might drop it here.
--------------------------------------

SELECT  usockId, usockCode, usockDesc, usockAmount
FROM   dbo.tbl_usocks
WHERE  usockDesc LIKE '%HANDSET%' 
AND usockCode NOT IN ('DCSB01','DCSB02')
ORDER BY usockCode, usockDesc

---------------------------------------

---------------------------------------

CREATE PROCEDURE dbo.DCS_handsets_selected
AS
DECLARE @usockList varchar(2000)

SELECT @usockList = usockCode
FROM tbl_dcs_handsets_selected
WHERE handsetid = 1

SELECT  usockId, usockCode, usockDesc, usockAmount
FROM   dbo.tbl_usocks
WHERE  usockDesc LIKE '%HANDSET%' 
AND usockCode  NOT IN ('@usockList')
ORDER BY usockCode, usockDesc

---------------------------------------

Thanks,
Dave




HTC Disclaimer:  The information contained in this message may be
privileged and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, you
are hereby notified that any dissemination, distribution or copying of
this communication is strictly prohibited.  If you have received this
communication in error, please notify us immediately by replying to the
message and deleting it from your computer.  Thank you.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Purchase from House of Fusion, a Macromedia Authorized Affiliate and support the CF 
community.
http://affiliates.macromedia.com/b.asp?id=2439&p=go/st_aff1

Message: http://www.houseoffusion.com/lists.cfm?link=i:6:1703
Archives: http://www.houseoffusion.com/lists.cfm?link=t:6
Subscription: http://www.houseoffusion.com/lists.cfm?link=s:6
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=<:emailid:>.<:userid:>.<:listid:>

                        

Reply via email to