Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help- Join question

Author  Topic 

sbt1
Yak Posting Veteran

89 Posts

Posted - 2005-01-20 : 15:52:25
I have this query:
SELECT
Tasks.Customer,JobNumber,convert(int,sum(CASE when Tasks.TaskType='Preventive Maintenance' then 1 else 0 end))as PM_Visits, convert(int,sum(CASE when Tasks.TaskType='Quality Assurance' then 1 else 0 end))as QA_Visits, convert(int,sum(CASE when Tasks.TaskType='Insight Software Upgrade' then 1 else 0 end)) as Insight_Upgrades
FROM Tasks
INNER JOIN TaskDates ON Tasks.TaskID = TaskDates.TaskID

Which works just fine, as long as there is an entry in the TaskDates table which corresponds to one in the Tasks table (with matching TaskID).

The problem is, I also need the query to return the Tasks.Customer field plus a 0 (zero) if there is no corresponding TaskID in the TaskDates field (which happens if there is a Task without any TaskDates (appointments) defined).

How can I do that?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-20 : 16:07:49
You'll need to use a LEFT OUTER JOIN to get the ones that don't match. You'll see NULL data for the rows not matching. Change the NULL data to whatever you need.

Tara
Go to Top of Page
   

- Advertisement -