Breaking resultset counts down.
Hey everyone, I have the below query giving me all of the correct results in my dataset; SELECT count(Inquiry.ID) as InqCount, Transfer.ReferredFrom, Transfer.ReferMcLean from Inquiry Inner Join Transfer on Transfer.TransferInquiryID_fk = Inquiry.ID WHERE (Inquiry.Date >= '4/1/2012' AND Inquiry.Date <= '8/23/2012') AND (Transfer.ReferMcLean = 'Appleton' OR Transfer.ReferMcLean = 'Brook' OR Transfer.ReferMcLean = 'Fernside' OR Transfer.ReferMcLean = 'Gunderson' OR Transfer.ReferMcLean = 'Hill Center' OR Transfer.ReferMcLean = 'OCDI' OR Transfer.ReferMcLean = 'Pavilion' OR Transfer.ReferMcLean = 'Lincoln') Group By Transfer.ReferredFrom, Transfer.ReferMcLean What I also need to do is get the resultset where the "ReferMcLean" column <> any of those values like this; SELECT count(Inquiry.ID) as InqCount, Transfer.ReferredFrom, Transfer.ReferMcLean from Inquiry Inner Join Transfer on Transfer.TransferInquiryID_fk = Inquiry.ID WHERE (Inquiry.Date >= '4/1/2012' AND Inquiry.Date <= '8/23/2012') AND (Transfer.ReferMcLean <> 'Appleton' AND Transfer.ReferMcLean <> 'Brook' AND Transfer.ReferMcLean <> 'Fernside' AND Transfer.ReferMcLean <> 'Gunderson' AND Transfer.ReferMcLean <> 'Hill Center' AND Transfer.ReferMcLean <> 'OCDI' AND Transfer.ReferMcLean <> 'Pavilion' AND Transfer.ReferMcLean <> 'Lincoln') Group By Transfer.ReferredFrom, Transfer.ReferMcLean These give me the data that is necessary to do my reports and report on if the ReferMcLean = (the above programs) or anything else. What I need is to figure out how to combine these into one query so that I can use the resultset in my report, because when I do my row grouping on the ReferredFrom column, some of the group values will equal 0 in the second dataset and not display if i group them both on ReferredFrom. Here is a screenshot of that. As you can see DataSet2 does not have any values for the OCDI program which leads to that row not being displayed. I want to display all of this data concurrently grouped on the ReferredFrom column, and displaying a 0 value in OCDI under the "Other Count" column, which is why I need the datasets combined into one query, but I unfortunately am not that much of a guru with SQL. If anyone can help that would be excellent. Thank you very much, NickG
August 25th, 2012 9:17am

This is actually a SQL question as opposed to an SSRS quesrion. SSRS doesn't combine queries. You'd have to do that yourself by writing them as a single query. Looking at your queries, you should be able to do that by using moving the filtering logic in your WHERE clause to CASE statements in your SELECT. HTH, JasonJason Long
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2012 9:26am

Nick: You can combine both results using UNION operator and make one result set. in both queries is there any specific reason you are using OR operator for almost 6 times to write same condition. instead of using and writing lengthy code you could use IN and Not IN operator to get same results. Regards, Chirag Patel (ETL Engineer @C-S-America)
August 25th, 2012 9:47am

I understand the UNION statement, but how can I use a union statement and be able to distinguish the counts between the two since the resultsets are combined? It will just reference InqCount for everything, not broken down for each query?
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2012 10:18am

Hey Jason, I know it's an SQL question, this forum is always just much more responsive to all questions and seem to do great with SQL related stuff as well. Is there any chance you could give me an example of Case statements in the select? I've just never used them in the past. Thank you, NickG
August 25th, 2012 10:28am

Sorry... Wasn't blowing off your last question. This is just turning out to be a busy day. I'll take a look at rewriting your SQL once I get some room to breathe.Jason Long
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2012 11:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics