Reputation: 1423
I have written below function to return max date
Alter function MAXdate(@DATE1 date,@DATE2 date,@DATE3 date)
returns date
as
begin
declare @max as date
set @max = ''
if(@DATE1> @DATE2)
set @max = @DATE1
else
set @max = @DATE2
if(@max >@DATE3)
set @max= @DATE3
return @max
end
But when i execute the function, I am not getting max value
select dbo.MAXdate('9/8/2008','12/1/2008','3/3/2008')
Can any one please help me analyse , why i am not getting max value?
Upvotes: 0
Views: 303
Reputation: 23238
if(@max >@DATE3)
set @max= @DATE3
should be
if(@DATE3>@max)
set @max= @DATE3
Upvotes: 2
Reputation: 28207
Your last test condition should be
if(@DATE3 > @max )
set @max= @DATE3
Upvotes: 7