SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 Displaying empty rows in a report
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

L_i_L_i
Starting Member

6 Posts

Posted - 10/20/2013 :  12:36:16  Show Profile  Reply with Quote
Hi!

I have a table that looks like this:

[Date] [Time interval] [Number of calls] [PilotID]

20130303 01:00-02:00 34 0100
20130303 01:00-02:00 23 0110
20130303 03:00-04:00 12 0100

etc....

My problem is that there are time intervals with no calls. But I want to show a report with 24 rows for time interval for every day. So if there are no calls, I want to show 0. PilotID and Date will be parameters. PilotID is a parameter with multiple values, so user can pick startdate and enddate and pilot(es). If u pick more than one pilot, the sum of calls will be shown (still 24 rows for a day). I don't know if those empty rows should be made in SQL, I tried Left Outer Join, but I couldn't get it right because of parameter used for PilotID. Any ideas how to deal with this?

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/20/2013 :  13:28:55  Show Profile  Reply with Quote

SELECT m.*,COALESCE(n.[Number of calls],0) AS [Number of calls]
FROM
(
SELECT [Date],[Time interval],PilotID
FROM (SELECT DISTINCT [Time interval] FROM Table)t
CROSS JOIN (SELECT DISTINCT [Date] FROM Table WHERE [Date] BETWEEN @StartDate AND @EndDate)d
CROSS JOIN (SELECT DISTINCT PilotID FROM Table WHERE PilotID IN (Your list values...))p
)m
LEFT JOIN Table n
ON n.PilotID = m.PilotID
AND n.[Date] = m.[Date]
AND n.[Time interval] = m.[Time interval]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

L_i_L_i
Starting Member

6 Posts

Posted - 10/22/2013 :  16:20:16  Show Profile  Reply with Quote
Thank you very much, you made my day! :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/23/2013 :  02:09:56  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000