Join Sales Header & Sales Invoice Header

jwilder
Member Posts: 263
How can I join the Sales Header and Sales Invoice Header in a single query and only return a distinct selection of order no's? I started with an Union query but it is not getting me a distinct list of all orders. Here is what I have so far:
Select SIH.[Order Date],
Case SIH.[Order Type]
When 0 Then 'Catalog'
When 1 Then 'Wholesale'
End,
SIH.[Order No_],
'SIH'
From [SWKTestWeb$Sales Invoice Header] As SIH
Where SIH.[Order Date] between '09/01/09' and '09/30/09' and SIH.[Order No_] <> ''
Union
select SH.[Order Date],
Case SH.[Order Type]
When 0 Then 'Catalog'
When 1 Then 'Wholesale'
End,
SH.No_,
'SH'
From [SWKTestWeb$Sales Header] as SH
Where SH.[Document Type] = 1
Any thoughts?
Select SIH.[Order Date],
Case SIH.[Order Type]
When 0 Then 'Catalog'
When 1 Then 'Wholesale'
End,
SIH.[Order No_],
'SIH'
From [SWKTestWeb$Sales Invoice Header] As SIH
Where SIH.[Order Date] between '09/01/09' and '09/30/09' and SIH.[Order No_] <> ''
Union
select SH.[Order Date],
Case SH.[Order Type]
When 0 Then 'Catalog'
When 1 Then 'Wholesale'
End,
SH.No_,
'SH'
From [SWKTestWeb$Sales Header] as SH
Where SH.[Document Type] = 1
Any thoughts?
Jason Wilder
jwilder@stonewallkitchen.com
jwilder@stonewallkitchen.com
0
Comments
-
Hello,
Doesn't the following code run correctly?Select DISTINCT SIH.[Order No_], From [SWKTestWeb$Sales Invoice Header] As SIH Where SIH.[Order Date] between '09/01/09' and '09/30/09' and SIH.[Order No_] <> ''
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 20050 -
That would only select order no's from posted invoices. If an order hasn't shipped yet this would miss those.Jason Wilder
jwilder@stonewallkitchen.com0 -
add a where not exists (in the sales invoice header)to your second select statement fdrom the sales headerDavid Machanick
http://mibuso.com/blogs/davidmachanick/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions