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 2005 Forums
 Transact-SQL (2005)
 MAKE CLEAR PLS

Author  Topic 

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-08-11 : 07:30:28
Hi

I have query like this..


DECLARE @L DECIMAL(38,2)

SELECT @L = 24.35





Query 1



IF @L - CONVERT(INT,@L) = 0

SELECT FLOOR (@L)

ELSE

SELECT @L







Query 2

SELECT

CASE

WHEN @L - CONVERT(INT, @L) = 0

THEN FLOOR (@L)

ELSE @L

END




I read below query some other blog..

He has using same logic but different coding pattern. But Will get different values …WHY

If am using FLOAT instead of decimal it's working fine..
or
If am using DECIMAL(4,2) its working fine.

Any one pls explain what it will happen...




-------------------------
R..
http://code.msdn.microsoft.com/SQLExamples/
http://msdn.microsoft.com/hi-in/library/bb500155(en-us).aspx

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-08-11 : 09:43:50
Its due to the size of your decimal and using a maximum precision of 38.

If you test twice more, once with 37 and then with 36, you will see the issue and be able to work out why this is so. Also, change your scale to 5 decimal places and change @L to be 5 decimal places, you will notice that only by decreasing the precision can you see the case version of @L. The numbers on precision and scale can add up to 38, but anything over 38 is ignored from the scale side as the precision takes precedence.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-08-11 : 17:06:03
You can also solve the issue by using proper CASTing..
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-08-12 : 04:01:20
You don't need to worry about CAST in this case as due to the precision, it won't work properly anyway.
Go to Top of Page
   

- Advertisement -