We help IT Professionals succeed at work.
Get Started

SQL Query Decimal Results

Harsh08 asked
Last Modified: 2012-05-11

The Query updates recordsets for the criteria at once . e.g . There are two recordsets  the query is supposed to update the IssRate. After executing the query the result shows :

    ID                     IssRate(float)
1. 1641900          77.44
2. 1642774          77.430824372759858      (expected 77.44)

I don't want query to round the amount to 2 decimals, because the issRate calculation is sometimes in decimals and not rounded

 Following query generates different results for different recordsets :

Update A
set IssRate =(select CASE WHEN (isnull(SUM(B.RecQty),0) - isnull(SUM(B.IssQty) ,0)) =0 THEN 0 ELSE (isnull(SUM(B.RecCost),0) - isnull(SUM(B.IssCost),0) ) /  (isnull(SUM(B.RecQty),0) - isnull(SUM(B.IssQty) ,0)) END from TransactionStock_WtdAvg B where B.ProductId = A.ProductId AND B.TransDate <= A.TransDate AND B.TransactionId <> A.TransactionId  
from TransactionStock_WtdAvg A
      ID IN (SELECT TOP (100) PERCENT ID from   TransactionStock_WtdAvg
      WHERE A.ProductId = @ProductId AND A.TransDate >= @EntryDate AND A.TransactionType = 13 AND ISNULL(IssQty, 0) <> 0 OR
      A.ProductId = @ProductId AND A.TransDate >= @EntryDate AND A.TransactionType = 16 AND ISNULL(IssQty, 0) <> 0 OR
      A.ProductId = @ProductId AND A.TransDate >= @EntryDate AND A.TransactionType = 22 AND ISNULL(IssQty, 0) <> 0

whats  wrong in the query?

Watch Question
This problem has been solved!
Unlock 1 Answer and 44 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE