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 2008 Forums
 Transact-SQL (2008)
 How to change query using In clause by passing a

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2010-03-17 : 02:20:53
How to change query using In clause by passing parameter havind id's
My id's are string type

declare @PKId varchar(255)

set @PKId = "MA000001 , MA000002 , MA000003 , MA000004"

I am passing @test parameter using ado.net/Enterprise library data access block

I wanted it to be executed like

select * from MyTable where MyStringPKId in
('MA000001' , 'MA000002' , 'MA000003' , 'MA000004')

Kamran Shahid
Sr. Software Engineer
(MCSD.Net,MCPD.net)

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-17 : 02:25:33
Please let us know if this thread helpful.

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2010-03-17 : 03:02:17
My problem is that I have a string type as the key
my field will not have special character.It is just alphanumeric

Kamran Shahid
Sr. Software Engineer
(MCSD.Net,MCPD.net)

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-17 : 03:05:39
read the link haroon posted.

Also http://www.sommarskog.se/arrays-in-sql-2005.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2010-03-17 : 05:14:24

it is a big article

Kamran Shahid
Sr. Software Engineer
(MCSD.Net,MCPD.net)

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-17 : 05:55:54
Read the first article link first then! There are choices to be made, vyaskn shows you what they are and I reckon that is a good article helping you to choose a suitable method.

If you have a large database, need best performance, and best-of-bred techniques then you need to read, and understand, the articles on Erland Sommarskog's site. But if your application is small, in house, not mission critical you can skip that class!
Go to Top of Page
   

- Advertisement -