June 11, 2009 at 7:50 am
create table emp(id int identity,name varchar(20),surname varchar(20))
insert into emp values('may','nk7')
insert into emp values('may1','nk6')
insert into emp values('may2','nk5')
insert into emp values('may3','nk4')
declare @list nvarchar(max);
set @list='1,2,3,4'
select name,surname
from emp
where id in(@LIST)
I want to pass @list at runtime.
Is it possible.
June 11, 2009 at 8:37 am
You could do it splitting the parameters into a table with a script like this:
http://www.sqlservercentral.com/scripts/T-SQL+Aids/31871/
There are lots around, even more efficient, with tally tables or with loops, just pick one.
create table emp(id int identity,name varchar(20),surname varchar(20))
insert into emp values('may','nk7')
insert into emp values('may1','nk6')
insert into emp values('may2','nk5')
insert into emp values('may3','nk4')
declare @list nvarchar(max);
set @list='1,2,3,4'
select name,surname
from emp
where id in(
SELECT Value
FROM [dbo].[fSplit](@list, ',')
)
Hope this helps
Gianluca
-- Gianluca Sartori
June 11, 2009 at 6:41 pm
mjarsaniya (6/11/2009)
select name,surnamefrom emp
where id in(@LIST)
I want to pass @list at runtime.
Is it possible.
I outline my favorite way in Using XML to Enhance the Performance of String Manipulations[/url].
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply