473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Querying 5 tables: SQL using MS query

I have the following tables with the following fields I need from each of these tables.

Customer table: fields: Customer Name, Customer No.

Sales Header table: fields: Customer No., Order Date, Job No.
Sales Invoice Header table: Customer No., Order Date, Order No., Job No.

Sales line table: Customer No.,Type, Qty, Unit Price, Line Amt, Job No.
Sales Invoice Line table: Customer, No., Type, Qty, Unit Price, Line Amt., Job No.
(the only difference between these last 2 tables is one is open orders and the other is closed orders so I need my query to pull all. I assume I need a "Union All" but I dont' know how to incorporate or get the needed links/information from the other 3 databases.

The fields I need to see upon running the query are:
Customer Name, Customer No., Order Date, Order No., Qty, Unit Price, Line Amt.

How do I get my SQL statement correct to pull the information from each database correctly. Thanks in advance. I've been working on this for 2 days and felt like I got close but no cigar.
Nov 17 '06 #1
3 2570
ronverdonk
4,258 Expert 4TB
If you are talking MSSQL you are in the wrong forum!

Ronald :cool:
Nov 18 '06 #2
willakawill
1,646 1GB
If you are talking MSSQL you are in the wrong forum!

Ronald :cool:
Hey Ronald, you lost me here. This is not MS SQL Server forum???
Nov 18 '06 #3
willakawill
1,646 1GB
I have the following tables with the following fields I need from each of these tables.

Customer table: fields: Customer Name, Customer No.

Sales Header table: fields: Customer No., Order Date, Job No.
Sales Invoice Header table: Customer No., Order Date, Order No., Job No.

Sales line table: Customer No.,Type, Qty, Unit Price, Line Amt, Job No.
Sales Invoice Line table: Customer, No., Type, Qty, Unit Price, Line Amt., Job No.
(the only difference between these last 2 tables is one is open orders and the other is closed orders so I need my query to pull all. I assume I need a "Union All" but I dont' know how to incorporate or get the needed links/information from the other 3 databases.

The fields I need to see upon running the query are:
Customer Name, Customer No., Order Date, Order No., Qty, Unit Price, Line Amt.

How do I get my SQL statement correct to pull the information from each database correctly. Thanks in advance. I've been working on this for 2 days and felt like I got close but no cigar.
Hi
There is a lot of redundancy in these tables. Same data in each.
To get the result that you want you only need to use 3 of the tables:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Customer].[Customer No]
  2. , [Sales Invoice].[Order Date]
  3. , [Sales Invoice].[Order No]
  4. , [Sales line].[Qty]
  5. , [Sales line].[Unit Price]
  6. , [Sales line].[Line Amt]
  7. FROM [Customer] C
  8. INNER JOIN [Sales Invoice] S
  9. ON C.[Customer No] = S.[Customer No]
  10. INNER JOIN [Sales line] L
  11. ON C.[Customer No] = L.[Customer No]
  12.  
  13.  
Hope this helps
Nov 18 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Elliot Rodriguez | last post by:
As I continue to read more about the benefits of database querying using ADO.NET, I am having a more difficult time distinguishing what the best approach to data retrieval is anymore. When...
2
by: Steve | last post by:
Hi; I am looking for suggestions about how to solve a problem using tsql. I have been asked to create a report concerning 4 tables. Each of the 4 tables is in its own database. The 4...
6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
0
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
3
by: loosecannon_1 | last post by:
I get a 90-120 second blocking when send 15 or so simultaneous queries to SQL Server 2000 that query a view made up of two joined tables. After each query is blocking for the same amount of time...
5
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an...
4
by: chitownjohn69 | last post by:
I'm working on a simple database that has 2 tables one called ITEMS, one called USERS. I'm tracking items being transfered between 2 users. in the ITEMS table I reference the sending user and...
1
by: SilRay | last post by:
I will admit up front that this is to help with an assignment for a class, however, I'm looking for information outside the scope of the assignment because I want to do something cooler. The...
4
by: mcmahon | last post by:
Hi, I have a MS Access DB with a query that I need to display in vb but am not too sure on how to go about it. The query has some criteria - i.e you have to input a date to run the query. I think...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.