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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Explain this ! (Math in SQL Server)

Author  Topic 

ngurukiran
Starting Member

3 Posts

Posted - 2012-01-23 : 11:59:53
I am sure that this will be an interesting discussion(at least for most SQL developers / DBA's). Try the below code in almost any version of SQL Server (SQl 2005 and upwards) and please let me know if this is explainable(I can assure you I have arguments and counter arguments to this and many more such code):


set nocount on
declare @num1 money
declare @num2 money
declare @num3 money

set @num1 = 2642.7100
set @num2 = 10739004.6800
set @num3 = 6694665.0000

select 'Calculated as literals, without variables : ', (2642.7100/10739004.6800)*6694665.000
SELECT 'Calculated with money variables(Wrong) : ', (@num1/@num2)*@num3


GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-23 : 12:05:42
Asked and answered: http://www.sqlservercentral.com/Forums/Topic1240302-392-1.aspx

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -