RE: How to pass param for IN() clause to sql command?



Great article, and glad to see that he/she/it is still around.

In the end, I can't write stored procedures since I am only allowed to report off the database, not modify it. I have to use SSRS, so that forces me to use DataSets. Ideally there would be a way to force the dataset's generated code to deal with an array (or hack it to). Since this is a SqlCommand at it's heart, one can hope. Modifying.augmenting the generated code turns out to be way to much of a maintenance and clarity problem.

In the end, I came up with this:
* Xml "Query" schema which supports parameters of type "Any" and "In" and a few others
* Individual files which contain the queries, and indicate which datatable they should "fill"
* Use XSD to generate classes for the Query.xsd file (It doesn't use use List(of T) for collections! )
* Loaders/etc to get them as Resources from the dll/deserialize/valiadate/etc
* A few shims to execute these, rename the tables they produce, and stick them into RS

So far it works. The format is pretty simple, just <query><params><param name=".." type="..."></><sql>blahbla @param blah blah</></> with a few other attributes here and there.

I didn't want to got his far, but at least now the process for creating it is straightfoward. Now, if only I could take these individual query files and generate the DataSet from them easily, and then modify the definitions contained in my SSRS report files!

Thanks again all,

//Andrew

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



.



Relevant Pages

  • Re: Report on a selected field value
    ... Quoting quotes is a confusing topic. ... DoCmd.OpenReport "EII_Report", acViewPreview,, strWhere ... EII_Acronym is the field I want the report based on. ... called up by the switchboard item "Location Report." ...
    (microsoft.public.access.reports)
  • zickige Fenster
    ... um z.B. REPORT PREVIEW oder MODIFY COMMAND in richtiger ... Beim REPORT PREVIEW ist, abhängig von der Vorgeschichte (ob ich z.B. ... Bei MODIFY COMMAND schalte ich die Resourcen-Datei ein, ...
    (microsoft.public.de.fox)
  • Re: Individual vs.whole dB locks on forms/reports during modificat
    ... Fix access so that users can once again modify forms while others are logged ... Employ per form and per report level locks exactly like the table locks so ... >> Here's another data integrity SNAFU, say a user opens a form for modify ...
    (microsoft.public.access.forms)
  • Re: Add ONE variable word to report header
    ... The reasons I suggested using the MsgBox instead of a prompt ... Place a Text Box in the report where you want the note. ... quotes problem you refer to here. ... The reason I want you to actually remove that code is to ...
    (microsoft.public.access.reports)
  • Re: Some pro-gunners STILL confused by CDC report
    ... They were there to support my ... Some pro-gunners STILL confused by CDC report ... Old quotes from specific people with no recent quotes from those ...
    (talk.politics.guns)