UDF for horizontal aggregate to get the minimum


SELECT [dbo].[fn__horizantal_min](Col1,
           [dbo].[fn__horizantal_min](Col2,
           [dbo].[fn__horizantal_min](Col3,
                                                 Col4)  as HorizontalMin 
 FROM testTable
 
The function is as below:

CREATE FUNCTION [dbo].[fn__horizantal_min]( @int1 int, @int2 int)

returns

int

as

begin

if @int1 is null

return @int2

if @int2 is null

return @int1

if @int1 < @int2

return @int1

else

return @int2

return null

end

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s