Monday, March 12, 2012

Is it possible

I have a .NET Web application that points to quite a few SQL reports.

Here is what I am looking to do:

I have a list of values that will change quite frequently. Say this is the list for example

A

B

C

D

E

In my report I need to say "where MyField = 'A' OR MyField = 'B' OR MyField = 'C'" .... etc.

The problem here is the list above is going to vary in value and *in number of parameters*. It won't always be 5 parameters...sometimes 6, etc. I won't know at compile time how many parameters.

***Is there a way to build the query for the Report in Visual Studio and have the report use that query for its dataset?***

Basically in Visual Studio I would say:

myQuery = "select whatever from wherever where MyField = FirstListValue "

While not at end of list

myQuery += "OR" + nextValue

End While

Has anyone done this before?

Are you using SQL Server 2005 and are you saying that it is a different number of values that can be in the same field? If so, just us a multi value parameter and in your SQL in the report add the clause: and MyField in (@.MyParm)

Then pass the values to the report in the MyParm parameter.

|||I'm fairly sure that is what I need. I'll give it a try and let you know how it turns out. Thanks!

No comments:

Post a Comment