RE: How to pass param for IN() clause to sql command?
- From: Kerry Moorman <KerryMoorman@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 15 Jan 2008 04:34:02 -0800
Andrew,
This article covers a lot of the options:
http://www.sommarskog.se/arrays-in-sql-2005.html
Kerry Moorman
"Andrew Backer" wrote:
How can I pass something that I want to use as a paramter in the "in" clause.
of a straight sql text query?
I have a SqlCommand that is of type .Text, and contains something like this"
.....SELECT * FROM dbo.Table WHERE date_id IN ( @date_id_list )
..... // date_id is an integer
I have tried passing this in: < 1','2','3','4 >, where there is a 'quote/comma/quote'
between each entry. This should at least put no single quote at the start
& end.
I suppose it is being helpful and "fixing" my quotes to double quotes <''>,
rendring my trickerly useless.
Is there a way to do this so that the SqlCommand won't do exactly what it
should be doing (sanitizing my input) on this parameter? I need IN clauses
a lot for this bit. In my case I am using a regular DataSet & DataAdapter,
so anything that fixes it there is even better, though I am not afraid to
modify the code. If I have to move to external queries, then I will, but
it would be nice to keep it all in the dataset. Right now, this is the only
thing stopping me.
// Andrew
- Follow-Ups:
- RE: How to pass param for IN() clause to sql command?
- From: Andrew Backer
- RE: How to pass param for IN() clause to sql command?
- References:
- How to pass param for IN() clause to sql command?
- From: Andrew Backer
- How to pass param for IN() clause to sql command?
- Prev by Date: Re: How to search Team Foundation Server?
- Next by Date: Transactions
- Previous by thread: Re: How to pass param for IN() clause to sql command?
- Next by thread: RE: How to pass param for IN() clause to sql command?
- Index(es):