detroitchassis
asked on
Report Services - SQL WHERE IN CONDTION?
I have a listbox in my asp.net form that I allow mulitple items to be selected. The items are passed back to my report through CategoryString Parameter. I want my SQL to return all the items selected (i.e. Clothing, Tools, Components...)
Under the report data tab I have the following sql:
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN ([+ Parameters!CategoryString. Value +]))
The default CategoryString is set to "Components"
When I run the SQL in the Data Tab window I get the following message:
Invalid Column Name '+ Parameters!CatagoryString. value +'
Paul
Under the report data tab I have the following sql:
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN ([+ Parameters!CategoryString.
The default CategoryString is set to "Components"
When I run the SQL in the Data Tab window I get the following message:
Invalid Column Name '+ Parameters!CatagoryString.
Paul
ASKER
I tried that same code, but it did not work for me. Let say @CategoryString is Clothing or Tools it works fine, but if @CategoryString is ToolsClothing nothing is returned. Any thoughts why
When you fill in that variable from your ASP.NET page can you add ' OR ' between each of the individual variables? I'll think about it more over the weekend and let you know if I think of anything new on Monday.
Greg
Greg
ASKER
Still nothing.
I have a non-query report parameter defined as follows:
Name: CategoryString
Prompt: CategoryString
Data type: String
Allow blank values checked
Non-queried label: Blank
Non-queried value: Parameters!CategoryString. Value
Default values: 'Clothing'
Here is my sql:
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN (@CategoryString))
When I run the query and enter:
@Year: 2003
@Month: 1
@CategoryString: Bike
The sql returns all the January, 2003 records with a category of Bike. However when I enter:
@Year: 2003
@Month: 1
@CategoryString: BikeClothing
No rows are returned. I'm trying to return both the Bike and Clothing category records. Any ideas on what I might be doing wrong. I appreciate the help so far. This is probably something simple I'm over looking.
Paul
I have a non-query report parameter defined as follows:
Name: CategoryString
Prompt: CategoryString
Data type: String
Allow blank values checked
Non-queried label: Blank
Non-queried value: Parameters!CategoryString.
Default values: 'Clothing'
Here is my sql:
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN (@CategoryString))
When I run the query and enter:
@Year: 2003
@Month: 1
@CategoryString: Bike
The sql returns all the January, 2003 records with a category of Bike. However when I enter:
@Year: 2003
@Month: 1
@CategoryString: BikeClothing
No rows are returned. I'm trying to return both the Bike and Clothing category records. Any ideas on what I might be doing wrong. I appreciate the help so far. This is probably something simple I'm over looking.
Paul
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried setting @CategoryString to Bike,Clothing and 'Bike','Clothing' in parameter field prompt when running the sql from the data tab. No results were returned. However this SQL does return the desired results. What am I missing?
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN ('Bike', 'Clothing'))
Here is the code from my program:
Dim URL As String
URL = "http://localhost/ReportServer?/Custom Reporting/Product Profitability"
URL += "&rs:Format=HTML4.0&rs:Com mand=rende r&rc:Param eters=fals e&rc:Toolb ar=false"
URL += "&rc:HTMLFragment=true"
URL += "&Year=" + YearListBox.SelectedValue
URL += "&Month=" + MonthListBox.SelectedValue
URL += "&Category=" + GetParameterMultiSelect(Ca tegoryList Box, "CategoryString").Value
'Pass the URL as a Web request
Dim request As HttpWebRequest = WebRequest.Create(URL)
request.Credentials = System.Net.CredentialCache .DefaultCr edentials
Try
'Write the response into a byte array
Dim response As HttpWebResponse = request.GetResponse() "THIS IS WERE I'M FAILING
Dim ReceiveStream As Stream = response.GetResponseStream ()
Dim read(512) As Byte
Dim bytes As Integer = ReceiveStream.Read(read, 0, 512)
'Clear the text of the Label control and then write the bytes
'from the byte array into the control's text property after encoding as UTF-8
Label1.Text = ""
While (bytes > 0)
Label1.Text += encode.GetString(read, 0, bytes)
bytes = ReceiveStream.Read(read, 0, 512)
End While
Catch ex As Exception
Label1.Text = "Error retrieving page"
End Try
This is what the URL value looks like when execution fails:
"http://localhost/ReportServer?/Custom Reporting/Product Profitability&rs:Format=HT ML4.0&rs:C ommand=ren der&rc:
Parameters=false&rc:Toolba r=false&rc :HTMLFragm ent=true&Y ear=2003&M onth=1&Cat egory='Bik e','Clothi ng'"
This is the error message:
The remote server returned an error: (500) Internal Server Error.
I still think this is something stupid I'm doing, but for whatever reason I cannot seem to put my finger on it.
SELECT *
FROM vProductProfitability
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN ('Bike', 'Clothing'))
Here is the code from my program:
Dim URL As String
URL = "http://localhost/ReportServer?/Custom Reporting/Product Profitability"
URL += "&rs:Format=HTML4.0&rs:Com
URL += "&rc:HTMLFragment=true"
URL += "&Year=" + YearListBox.SelectedValue
URL += "&Month=" + MonthListBox.SelectedValue
URL += "&Category=" + GetParameterMultiSelect(Ca
'Pass the URL as a Web request
Dim request As HttpWebRequest = WebRequest.Create(URL)
request.Credentials = System.Net.CredentialCache
Try
'Write the response into a byte array
Dim response As HttpWebResponse = request.GetResponse() "THIS IS WERE I'M FAILING
Dim ReceiveStream As Stream = response.GetResponseStream
Dim read(512) As Byte
Dim bytes As Integer = ReceiveStream.Read(read, 0, 512)
'Clear the text of the Label control and then write the bytes
'from the byte array into the control's text property after encoding as UTF-8
Label1.Text = ""
While (bytes > 0)
Label1.Text += encode.GetString(read, 0, bytes)
bytes = ReceiveStream.Read(read, 0, 512)
End While
Catch ex As Exception
Label1.Text = "Error retrieving page"
End Try
This is what the URL value looks like when execution fails:
"http://localhost/ReportServer?/Custom Reporting/Product Profitability&rs:Format=HT
Parameters=false&rc:Toolba
This is the error message:
The remote server returned an error: (500) Internal Server Error.
I still think this is something stupid I'm doing, but for whatever reason I cannot seem to put my finger on it.
WHERE (Year = @Year) AND (MonthNumberOfYear = @Month) AND (Category IN (@CategoryString))
HTH,
Greg