November 27, 2002 at 1:35 pm
I am trying to get a string literal of comma seperated values to be parsed as a list of values by the "IN" statement. @param1 has a literal of seperated values, I am trying to get each value evaluated seperatly, but the T-SQL treats the whole string as a literal. ANyone have a work around? This parameter would be dynamic in that the values are never known ahead of time and there could be 0-n which prevents me from running a sp multiple times from program code for scaling reasons. Thanks!
ALTER PROCEDURE dbo.StoredProcedure1
@param1 varchar (1400)
AS
/* CANNOT USE A 'LIKE' EXPRESSION: I WANT TO FIND ALL RECORDS WHERE
ANY OF THESE COMMA SEPERATED VALUES APPEAR IN FIELD FNAME*/
SET @Param1 = 'joe,john,jay'
SELECT FULLNAME FROM USERS WHERE fname IN (@param1)
RETURN
November 27, 2002 at 6:25 pm
Try this:
SELECT
FullName
FROM Users
WHERE CHARINDEX(fname, @Param1) > 0
K. Brian Kelley
http://www.truthsolutions.com/
Author: Start to Finish Guide to SQL Server Performance Monitoring
http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1
K. Brian Kelley
@kbriankelley
November 27, 2002 at 6:29 pm
After looking at the other topics in the T-SQL forum, this is actually a duplicate question with a different topic title. Continue the thread in the following discussion:
K. Brian Kelley
http://www.truthsolutions.com/
Author: Start to Finish Guide to SQL Server Performance Monitoring
http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1
K. Brian Kelley
@kbriankelley
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply