We help IT Professionals succeed at work.
Get Started

Matrix columns (week numbers) and rows with no data but want to display ?

Steve Jebson
Steve Jebson asked
on
561 Views
Last Modified: 2012-05-10
Hi,

I'm trying to build a Matrix that shows week numbers across the top with a list of Sites that contain Lufts on the left. I want to show how many Callouts/Jobs have been created in each week. I've got that working but if there were no Callouts/Jobs in a week I'd still like to show that week column, similarly if there were no Callouts/Jobs for a particular Site/Lift i would still like to show that blank row.

I think i need to somehow select all Weeknumbers in a date range and Join that in some way to my main query and also include Sites/Lifts with no data in my main query ??

I've been trying all sorts of joins/sub queries but can't get it, can anybody help me please ?

here's the sql for my main query...


 
SELECT 
	s.id sId,
    l.id lId,
	count(c.ID) cCount,
    DATEPART (week,c.datetimereported) cReportedWeek,
	CASE
	 WHEN l.liftshortname is Null THEN ' ** Site Level ** '
	 ELSE l.liftshortname
	END lLift

FROM   site s
       LEFT JOIN job j
         ON s.id = j.siteid
       INNER JOIN callout c
         ON j.id = c.jobid
       INNER JOIN jobline jl
         ON j.id = jl.jobid
       LEFT JOIN lift l
         ON jl.liftid = l.id
WHERE  ( c.datetimereported BETWEEN '01/01/2010' AND '12/12/2010' )
       AND ( s.id IN (SELECT id
                         FROM   site s
                         WHERE  ( contractid = 3005 )) )

group by DATEPART (week,c.datetimereported), s.id, l.id, l.liftshortname

Open in new window

Comment
Watch Question
Database Administrator
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE