troubleshooting Question

Difficult Query.....

Avatar of kevp75
kevp75Flag for United States of America asked on
Microsoft SQL ServerXMLSQL
12 Comments3 Solutions325 ViewsLast Modified:
This one may be a little difficult to explain, so please bear with me as I attempt to do so...

I am trying to generate a XML file as an export of my Invoicer's list of invoices.  What I am wondering is how I can get the $ totals correct in the query.

Right now I have 5 Tables that are related for this, I will give the general layout:

iID >pk, increment 1
iInvoiced >datetime, getdate()

rID >pk, increment 1
rRate >money

invID >pk, increment 1
invName >nvarchar, the parts name
invCost >money, the cost....

itID >pk, increment 1
iID >int, relates to tblInvoices
rID >int, relates to tblPayRate
rQuan >int, #of hours

ipID >pk, increment 1
iID >int, relates to tblInvoices
invID >int, relates to tblInventory
ipQuan >int, #of pieces

tipID >pk, increment 1
iID >int, relates to tblInvoices
tipAmount >money

Now, what makes this query difficult, is the fact that not only do I have to relate all these tables into a single query (I'm assuming a JOIN would be in order), but I also need to get the totals for each related table (tblInvoiceTime - need total $, tblInvoiceParts - need total $ + value from taxRate(which I get from a seperate table based on where the client is located), and tblInvoicePayments - total $), and then total everything together to get an balance due.

I have a function to generate my XML export that excepts a SQL Query as one of the parameters  (<---don't really think this is relevant, but may be nice to know...)

How can I do this without pulling my (and possibly yours) hairs out?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros