Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable IN
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Miscellaneous
Thread ID:
00834228
Message ID:
00834232
Views:
38
It can be done in many ways (shown in the order of my personal preferences) :
1. Using XML. See Re: IN and char versus int Thread #833306.
2. Using fn_split() function from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlmag01/html/TreatYourself.asp to convert a list into a table and than use derived table in your select
3. Use dynamic sql.
DECLARE @Sql nvarchar(4000)
SET @Sql = 'SELECT ... WHERE column in (' + @ListParam + ')' 
EXECUTE(@Sql)
>I have a procedure that has a SELECT statement in it using the IN predicate.
>
>SELECT ...
> WHERE column in ('11','12',...)
>
>I want to pass the '11','12',... as a parameter to the procedure.
>
>Right now, I end up having 6 different procedure just to handle the dirrefrent IN values.
>
>Can the IN predicate be sed with a variable ?
>
>I do not know if dynamic SQL could bu used, nor how ;-)
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform