SQL MAX of multiple columns?

后端 未结 22 1857
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 02:03

How do you return 1 value per row of the max of several columns:

TableName

[Number, Date1, Date2, Date3, Cost]

I n

22条回答
  •  遥遥无期
    2020-11-22 02:25

    here is a good solution:

    CREATE function [dbo].[inLineMax] (@v1 float,@v2 float,@v3 float,@v4 float)
    returns float
    as
    begin
    declare @val float
    set @val = 0 
    declare @TableVal table
    (value float )
    insert into @TableVal select @v1
    insert into @TableVal select @v2
    insert into @TableVal select @v3
    insert into @TableVal select @v4
    
    select @val= max(value) from @TableVal
    
    return @val
    end 
    

提交回复
热议问题