Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Pass Multiple values

Author  Topic 

ranalk
Starting Member

49 Posts

Posted - 2010-05-13 : 01:23:34
Hi,

I will give and example of my current case:

DECLARE @NAME VARCHAR(15)
SET @Name = ''
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
SELECT * FROM Employee e
WHERE e.Name = @Name

I want to pass few name in the same time, so how can I put it into the one parameter?
i want it to run in the following format:
DECLARE @NAME VARCHAR(15)
SET @Name =

SET TRANSACTION ISOLATION LEVEL SNAPSHOT
SELECT * FROM Employee e
WHERE e.Name IN @Name

Thanks!

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-05-13 : 01:28:27
Use Dynamic SQL

DECLARE @NAME VARCHAR(15)
SET @Name = '''a'',''b'''

exec ('Select * from Employee e where e.name in ('+@Name+')')

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

mrm23
Posting Yak Master

198 Posts

Posted - 2010-05-13 : 01:29:39
i think you can use comma separated variables....
i have used it to pass multiple values into the parameters. write a function to split the data as CSV and then write : WHERE @Name in (select from that SPLIT Function)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-13 : 10:52:29
or simply do

SELECT * FROM Employee e
WHERE ',' + @Name + ',' LIKE '%,' + e.Name + ',%'

and pass value in csv format

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -