Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 2nd, 2004, 04:15 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default T-SQL Outer join query

I have the following query, where I am trying to get all rows for a specifiec job number from a table named DeliveryDetails and the deliverynote number if it exists and isn't cancelled (i.e. dn.Cancelled = 0):

Code:
SELECT dd.*, dn.DeliveryNoteNumber
FROM DeliveryDetails dd FULL OUTER JOIN DeliveryNotes dn
ON dd.DeliveryNumber = dn.DeliveryNumber
WHERE dd.JobNumber = '60123' AND dn.Cancelled = 0
ORDER BY dd.DeliveryDate, dd.DeliveryNumber
This only returns rows from DeliveryDetails where there is a deliverynote, because I have specifed that dn.Cancelled should be false (0). What I need to do is write a query to the effect 'dn.jobnumber = xxxx and if dn.DeliveryNumber is not null then dn.cancelled = 0' but obviously this doesn't work. Is this possible?

 
Old June 2nd, 2004, 06:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You may use this in that case.

SELECT dd.*, dn.DeliveryNoteNumber
FROM DeliveryDetails dd FULL OUTER JOIN DeliveryNotes dn
ON dd.DeliveryNumber = dn.DeliveryNumber
WHERE dd.JobNumber = '60123' AND dn.Cancelled = 0
AND dn.DeliveryNumber is not NULL
ORDER BY dd.DeliveryDate, dd.DeliveryNumber

Hope that Helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 2nd, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I don't think this does what he wants...

Perhaps:

Code:
WHERE dd.JobNumber = '60723' AND (dn.Cancelled=0 OR dn.DeliveryNumber is null)
Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old June 2nd, 2004, 09:37 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

That's brilliant Hal. Thanks very much to both of you!

 
Old June 2nd, 2004, 09:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

It worked? Wow.... I answered one correctly :)

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old June 2nd, 2004, 10:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Great Hal,

Actually I was think of posting the one you did, But was not sure what data would be there in dn.DeliveryNumber if CANCELLED=0. Then gave this one. Had that not worked for him and had you not anwered him with this, I would be forced to post the one you did;). Anyways, he got that, and you too are happy that it worked

Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't figure out an OUTER JOIN statement dhsmd SQL Language 5 September 18th, 2008 01:02 AM
left outer join keyvanjan Classic ASP Basics 1 April 15th, 2006 05:37 AM
left outer join keyvanjan Classic ASP Professional 0 February 5th, 2006 11:54 AM
Outer Join, 2 columns jking SQL Language 1 December 5th, 2004 04:14 AM
outer join on same table roog SQL Language 4 September 30th, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.