Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parameter and IN Operator
Message
From
08/12/2007 06:18:20
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
27/11/2007 16:06:20
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01271545
Message ID:
01274136
Views:
11
>What is the proper way to pass a list of values via parameter to an IN operator? We have tried the following as a query in the management studio with no luck. The error message returned is as follows:
>
>Msg 102, Level 15, State 1, Line 3
>Incorrect syntax near ','.
>
>
>
>
>declare @joblist as varchar(100)
>
>set @joblist ='006291','006411'
>SELECT * FROM jcprod where cjobno in (@joblist)
>
>
>
>
>Thanks In Advance
>
>Jeff Hibbs
>The Blencowe Group

Jeff,
Using a table variable is better IMHO. ie:
declare @joblist table (jobid varchar(100))
insert into @joblist values ('006291')
insert into @joblist values ('006411')
SELECT * FROM jcprod innner join @joblist jl on jcprod.cjobno = jl.jobid
Also this approach would be ready for new SQL2008 table parameters.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform