Advertisement

06.24.2008 at 11:02AM PDT, ID: 23511952
[x]
Attachment Details

SQL calculation problem

Asked by Wytech_Wire in MS SQL Server, SQL Query Syntax, SQL Server 2005

Tags: Microsoft, SQL, 200 & 2005

I am trying to have this query calculate how much stock we have of a specific alloy, with the query below I should be getting a result of 81.57 but I am only getting 41.66. Somewhere it is dropping rows and I just cannot figure it out. When I structure these queries by themselves I get the correct calculation. It is only when I try to combind them that I get the lower result.

There are three tables involved:
tblAlloys = which hold the Alloy Name
tblInvTag = which hold the Stocks original values
tblInvXaction = which holds withdraws from the Inventory (Generally Negative numbers ex. -.91)Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
SELECT DISTINCT tblInvTag.Diam AS Diams, SUM(DISTINCT tblInvTag.QtyOrig) + SUM(DISTINCT tblInvXaction.ActionQty) AS Leftover
FROM tblInvTag INNER JOIN
tblAlloys ON tblInvTag.AlloyID = tblAlloys.ID 
INNER JOIN
tblInvXaction ON tblInvTag.Tag# = tblInvXaction.InvTag
WHERE
(tblInvTag.Status = 'open') AND (tblInvTag.Diam BETWEEN '.02' AND '.02') AND (tblAlloys.DescShrt = '304V S/S')
GROUP BY tblInvTag.Diam
ORDER BY tblInvTag.Diam
[+][-]06.24.2008 at 11:08AM PDT, ID: 21858521

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 11:26AM PDT, ID: 21858693

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 11:57AM PDT, ID: 21859084

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:06PM PDT, ID: 21859192

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:06PM PDT, ID: 21859204

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:08PM PDT, ID: 21859224

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:17PM PDT, ID: 21859332

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Query Syntax, SQL Server 2005
Tags: Microsoft, SQL, 200 & 2005
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.24.2008 at 12:18PM PDT, ID: 21859341

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:25PM PDT, ID: 21859426

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 12:37PM PDT, ID: 21859554

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 01:07PM PDT, ID: 21859887

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628