SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmeds08
Aged Yak Warrior

India
573 Posts

Posted - 12/21/2012 :  11:04:22  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Dear All,
Need help on the below query.
I have pulled this script from postgres database and modifed in sql sever.
output in postgres=0.00273785078713210130
output in sql server=0.00273972602739726
the logic is the same as in postgres,not understanding what is the issue in this query
please help me
the data type for @u and @t in postgres is just numeric,i have taken as float in sql server

declare @u float=1
declare @t float=2
declare @d VARCHAR(255)='N'

DECLARE @Output float

IF @u > @t * (365.25/12)
BEGIN
SELECT @Output=1
END
ELSE IF @t <= 0 OR @u <= 0
BEGIN
SELECT @Output=0
END
ELSE IF (@d = 'N' and @t < 85) or (@d = 'U' and @t <61)
BEGIN

SELECT @Output = (earnlo + (earnhi - earnlo) * ( @u - expdayslo) / (expdayshi - expdayslo) )
FROM rm_vscearn
WHERE @u BETWEEN expdayslo AND expdayshi AND @t BETWEEN termlo AND termhi AND @d = newused

END
ELSE
BEGIN
SELECT @Output = @u/(@t * (365.25/12))
END

select @Output

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 12/21/2012 :  11:24:22  Show Profile  Reply with Quote
float is approximate numeric datatype so if you want accuracy till particular decimal place use numeric or decimal datatype instead

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ahmeds08
Aged Yak Warrior

India
573 Posts

Posted - 12/21/2012 :  11:29:12  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
quote:
Originally posted by visakh16

float is approximate numeric datatype so if you want accuracy till particular decimal place use numeric or decimal datatype instead

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Hi Visakh,
I tried using numeric(22,20) but i get output as 0.00273900000000000000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 12/21/2012 :  11:48:59  Show Profile  Reply with Quote
the result will be corrected to highest significant figure among operands. so check the values of fields involved in the calculation and see if they've required precision and scale.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ahmeds08
Aged Yak Warrior

India
573 Posts

Posted - 12/21/2012 :  11:57:56  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
quote:
Originally posted by visakh16

the result will be corrected to highest significant figure among operands. so check the values of fields involved in the calculation and see if they've required precision and scale.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Thanks for the reply.
all the fields involved in the calculation have integer values,they don't have any decimal value in the table.
so,how do i achieve the required output.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 12/21/2012 :  14:06:19  Show Profile  Reply with Quote
cast them to required decimal then

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4612 Posts

Posted - 12/21/2012 :  14:57:40  Show Profile  Reply with Quote
I'm not sure if you are running into an "issue" were SQL changes the precision when performing operations. Here is a link for more detail:
http://msdn.microsoft.com/en-us/library/ms190476.aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000