Advertisement

07.07.2008 at 02:53PM PDT, ID: 23544925
[x]
Attachment Details

LEFT JOIN not working as expected - SQL Server 2000.

Asked by dbbishop in MS SQL Server, SQL Query Syntax

I have the code below. I happen to know that in the table WorkOrders I have one workorder that has three rows, one with a WorkorderStatusCode of 'O', 'R' and 'C' respectively. In the table AccessWorkorders there is only an 'R' and 'C' record. I would think the query below would provide me with the 'O' record from the first table, but it is not returning any data. What am I overlooking here?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
select s.* 
from dbo.WorkOrders s
left outer join dbo.AccessWorkorders a
on s.WorkorderNumber = a.[WO Number] 
and cast(convert(char(10), s.WorkorderEntryDate, 120) as smalldatetime) = a.[Date Entered]
and s.PtnrAccountNumber = a.[Partner Account] 
AND s.ResidentName = a.[Resident Name] 
AND s.HomePhoneNumber = a. [Home TN]
and s.BusinessPhoneNumber = a.[Business TN] 
and s.AccountNumber = a.[BTN] 
and s.WorkorderTypeCode = a.[Work Order Type] 
and coalesce(s.CampaignCode, '') = coalesce(a.[Campaign], '') 
and s.WorkorderStatusCode = a.[Work Order Status] 
and s.ScCvvActIndicator = a.[Equipment Flag] 
and coalesce(s.WorkorderCompletionDate, '1900-01-01') = coalesce(a.[Completion Date], '1900-01-01')
and s.WorkorderReasonCode = a.[Work Order Reason 1]
where a.[wo number] is null
and a.[wo number] not like '%_1000_%' 
and cast(convert(char(10), s.WorkorderEntryDate, 120) as smalldatetime) = '2007-12-07'
[+][-]07.07.2008 at 03:30PM PDT, ID: 21949193

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 03:32PM PDT, ID: 21949208

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 04:09PM PDT, ID: 21949378

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Query Syntax
Sign Up Now!
Solution Provided By: folderol
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.07.2008 at 04:12PM PDT, ID: 21949394

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 04:13PM PDT, ID: 21949398

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 04:13PM PDT, ID: 21949402

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2008 at 04:14PM PDT, ID: 21949406

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906