Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Update

Author  Topic 

boswellg
Starting Member

1 Post

Posted - 2010-06-10 : 16:09:20
I'm stuck on a really basic query and could use some help. I'm going to feel stupid when I see the answer.

UPDATE Products
SET Products.ReorderLevel = ROUND((2*(Suppliers.LeadTime /22))*Products.Trend,2)
FROM Products INNER JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID

ReorderLevel, LeadTime, and Trend are all INT

This ALWAYS returns 0 for the ReorderLevel but that's not accurate. For example, if the Trend is 20 and the lead time is 6 it updates ReorderLevel to zero but it should be 11.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-06-10 : 16:25:13
You are doing integer math instead of decimal math (see difference below).

You should read about both in SQL Server Books Online.
select
Integer_Math_Result = ROUND((2*(6 /22))*20,2),
Decimal_Math_Result = ROUND((2*(6.0 /22.0))*20.0,2)

Results:
Integer_Math_Result Decimal_Math_Result 
------------------- -------------------
0 10.9100000

(1 row(s) affected)





CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-11 : 02:53:44
Also refer this post
http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -