Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
SQL
declare @diff float
set @diff=0.8
if (@diff>=0.0) and (@diff<0.3) 
begin
 	set @diff=0.0
print 'a'
end
else 
	if (@diff>=0.3) and (@diff<0.8)
begin
 	set @diff=0.5
print 'b'
end
	if @diff >= 0.8 
begin
 	set @diff=1.0
print 'c'
end
print @diff

----------------------------------------------------

SQL
declare @monthdays float
declare @lgwdays int --legalworkingdays
declare @lgpdays float --legalpresentworkingdays
declare @diff float
set @diff=0
set @monthdays=day(dateadd(mm,datediff(mm,-1,'30-09-2011'),-1))
set @lgwdays=@monthdays-4
set @lgpdays=(9/@monthdays)*@lgwdays
set @diff=round(@lgpdays,2)-floor(@lgpdays)
print @diff
if (@diff>=0.0) and (@diff<0.3) 
begin
 	set @diff=0.0
print 'a'
end
if (@diff>=0.3) and (@diff<0.8)
begin
 	set @diff=0.5
print 'b'
end
if (@diff>=0.8) 
begin
 	set @diff=1.0
print 'c'
end
print @diff

------------why the output is different for above 2 functions with same values
Posted
Updated 1-Jan-12 19:52pm
v2
Comments
uspatel 2-Jan-12 1:53am    
pre tag added....

1 solution

Probably because they contain different logic.
The top one has an else condition the bottom one lacks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900