Wednesday, March 7, 2012

how to get minimum value from a list of user defined values

i've three variables in my stored proc. & i want get the least of them.
i know i can do that using case or if statements but i want to does
T-SQL provides any other way of doing it.
regards,
rameshHere you go
DECLARE @.num1 int
DECLARE @.num2 int
DECLARE @.num3 int
SET @.num1 = 5
SET @.num2 = 3
SET @.num3 = 7
SELECT Min(Num)
FROM
(SELECT @.num1 AS Num
UNION ALL
SELECT @.num2
UNION ALL
SELECT @.num3) T
Regards
Roji. P. Thomas
http://toponewithties.blogspot.com
<rameshsaive@.gmail.com> wrote in message
news:1139377057.261785.191850@.f14g2000cwb.googlegroups.com...
> i've three variables in my stored proc. & i want get the least of them.
> i know i can do that using case or if statements but i want to does
> T-SQL provides any other way of doing it.
>
> regards,
> ramesh
>

No comments:

Post a Comment