TSQL can do it, but it takes a little prep...
First, you need a function:
(it takes a comma-delimeted string of integers, and returns the greatest integer)
CREATE Function [dbo].[GreatestInt]
( @Array varchar(max) )
Returns int As
BEGIN
DECLARE @end Int
DECLARE @start Int
DECLARE @tbl_int Table (myInt Int)
DECLARE @return Int
SET @Array = @Array + ','
SET @start=1
SET @end=1
WHILE @end<Len(@Array)
BEGIN
SET @end = CharIndex(',', @Array, @end)
INSERT INTO @tbl_int
SELECT
Cast(Substring(@Array, @start, @end-@start) As Int)
SET @start=@end+1
SET @end = @end+1
END
SET @return = (SELECT MAX(myInt) FROM @tbl_int)
RETURN @return
END
And then to create your string of integers (this is the part TSQL isn't very good at):
(in the SELECT)
stuff(
stuff([num5], 1, 0,',')
,1,0,
stuff(
stuff([num4], 1, 0,',')
,1,0,
stuff(
stuff([num3], 1, 0,',')
,1,0,
stuff(
stuff([num2], 1, 0,',')
,1,0,
[num1]
)
)
)
)
So to use the function:
SELECT
id,
dbo.GreatestInt( stuff(
stuff([num5], 1, 0,',')
,1,0,
stuff(
stuff([num4], 1, 0,',')
,1,0,
stuff(
stuff([num3], 1, 0,',')
,1,0,
stuff(
stuff([num2], 1, 0,',')
,1,0,
[num1]
)
)
)
)
)
FROM
myTable
The reason I did it like this, instead of the way @mikael did in his answer (wich I +1'd, because it does answer your question), is that this approach will work on any number of fields, not just 5. But honestly, TSQL does have some room to improve here -- they really need a tsql version of plsql's greatest/least functions. Oh well...