Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

parameter question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon - 03 Jan 2006 20:19 GMT
Is it possible to use a parameter in conjuntion with an IN statement?

For example, if  I have the following SQL,
select * from table where key in ('1','2','3')

How can I make the values in the IN be a param?  If I do the following.
select * from table where key in (@invals)

I can't make a parameter like so,
param = new sqlparameter("@invals","'1','2','3'")
It simply returns no results.

Is there a way to make a parameter that will work?

Thanks
Marina - 03 Jan 2006 20:24 GMT
You can't, there is no way to do this as far as i know. You have to
concatenate the strings together for the query.

> Is it possible to use a parameter in conjuntion with an IN statement?
>
[quoted text clipped - 11 lines]
>
> Thanks
Jon - 03 Jan 2006 20:50 GMT
Darn, that's what I figured.  Thanks

> You can't, there is no way to do this as far as i know. You have to
> concatenate the strings together for the query.
[quoted text clipped - 14 lines]
>>
>> Thanks
W.G. Ryan - MVP - 03 Jan 2006 21:13 GMT
http://support.microsoft.com/default.aspx?scid=kb;en-us;555167
> Is it possible to use a parameter in conjuntion with an IN statement?
>
[quoted text clipped - 11 lines]
>
> Thanks
William (Bill) Vaughn - 04 Jan 2006 00:40 GMT
Yes, this is an interesting approach and I have another I talk about in my
book that uses a Table-type Function to parse the delimited string...

Signature

____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

> http://support.microsoft.com/default.aspx?scid=kb;en-us;555167
>> Is it possible to use a parameter in conjuntion with an IN statement?
[quoted text clipped - 12 lines]
>>
>> Thanks
Jon - 04 Jan 2006 16:12 GMT
Thanks.  This would work well in stored procedures, but unfortunately I am
using regular sql sentences.

> http://support.microsoft.com/default.aspx?scid=kb;en-us;555167
>> Is it possible to use a parameter in conjuntion with an IN statement?
[quoted text clipped - 12 lines]
>>
>> Thanks
Fox - 14 Jan 2006 12:19 GMT
Hi

the solution is next ->

DECLARE @smallSQL
SET @smallSQL = "SELECT * FROM Main WHERE Price IN "+@Params
Exec (@smallSQL)
========
Where @Params can be input value of proc like (1,2,3)

:-)

good luck

> Is it possible to use a parameter in conjuntion with an IN statement?
>
[quoted text clipped - 11 lines]
>
> Thanks
W.G. Ryan eMVP - 15 Jan 2006 03:22 GMT
Another possible approach is to do the following:
http://support.microsoft.com/default.aspx?scid=kb;en-us;555167 .  The guy
that wrote the article is a real genius so I figured I'd take this
opportunity to plug his article ;-)
> Hi
>
[quoted text clipped - 25 lines]
>>
>> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.