Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select statement question...
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
SQL Select statement question...
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01399790
Message ID:
01399790
Views:
104
I have four tables:

Orders_header, Orders_detail, Inovoice_header, Invoice_detail.

Making a long sad story short - some of the invoices don't have all the item details because the item wasnt shipped, but of course NOW someone needs a report showing the item anyway - with a quantity of zero. To make matters worse - it all needs to be done in one SQL Statement....which is where I'm stuck. Anoying because I've actually done this before - just can't remember how the heck I did it..grrrr

So...tables look like this:

Orders_header
-------------------
MasterNum N(10)
OrderNum N(10)

Orders_detail
------------------
OrderNum N(10)
ItemID C(3)
LineItemNum N(3)
QuantityOrdered N(3)

Invoice_header
--------------------
MasterNum N(10)
InvoiceNum N(10)

Invoice_Detail
--------------------
InvoiceNum N(10)
ItemID C(3)
LineItemNum N(3)
QuantityShipped N(3)


....and I want the output too look something like this:

OrderNum InvoiceNum ItemID LineItemNo QuantityOrdered QuantityShipped
1 1 A 1 10 10
1 1 B 2 15 12
2 2 C 1 8 8
2 2 D 2 5 0

...if that makes any sense at all. So you can have multiple inovices per order, and in some cases there will be fewer line-items in the invoice_detail compared to the order_detail, because only shipped items get written to the invoice_detail table..

Seems to me, that with a few left-outer joins you should be able to do this in one SQL statement - but that stupid ZERO and missing record from th invoice_detail table screws me up - and for the life of me I cant recall how I got around this before...

Anyone have any suggested SQL statements here???

Thanks!
ICQ 10556 (ya), 254117
Next
Reply
Map
View

Click here to load this message in the networking platform