Groups | Blog | Home
all groups > sql server mseq > february 2007 >

sql server mseq : it maybe a wrong return value



Lorry Astra
2/6/2007 3:40:02 AM
There is a sql function like this below:

Create Function dbo.abc
(@ParamOne decimal, @ParamTwo decimal)
RETURNS Bit
AS
BEGIN
DECLARE @Result bit
if abs(@ParamOne-@ParamTwo)<0.01
SET @Result=1
else
SET @Result=0
RETURN @Result
END

if i execute this sentence: "select dbo.abc (2.12,2.11)" , why does the
function return 1 instead of 0?
Thanks.


Hari Prasad
2/6/2007 7:15:01 AM
Please give the precision and scale while using decimal. See the below
example.

ALTER Function dbo.abc

(@ParamOne numeric(10,2), @ParamTwo numeric(10,2))

RETURNS Bit

AS

BEGIN

DECLARE @Result bit

if abs(@ParamOne-@ParamTwo)<0.01

SET @Result=1

else

SET @Result=0

RETURN @Result

END



Thanks

Hari

[quoted text, click to view]

AddThis Social Bookmark Button