SQL/TSQL 存储过程和函数 输出组成的最大数

图片说明
具体要求如上图所示,输入4个数字,每个数字在0-9之间,自定义一个GetMax函数,要求输出4个数组成的最大整数,如输入四个数为7,8,3,4,最后输出8743

CREATE FUNCTION GetMax(
@a int,
@b int,
@c int,
@d int
)
RETURNS INT
AS
BEGIN
?????
END

SELECT dbo.GetMax(7,8,3,4)

具体实现代码该如何编写?求教,虽然看起来容易,但对于小白还是有点困难的,请大佬们给予解答

CREATE FUNCTION GetMax(@a int,@b int,@c int,@d int)
RETURNS INT
AS

BEGIN
declare @str varchar(4000)
declare @tmp table(n varchar(100))
set @str =''

insert into @tmp
select @a union all 
select @b union all 
select @c union all 
select @d

SELECT @str = @str + n FROM @tmp order by n desc 
RETURN CAST(@str AS INT)

END

--SELECT dbo.GetMax(7,8,3,4)

CREATE FUNCTION GetMax(
@a int,
@b int,
@c int,
@d int
)
RETURNS int
AS
BEGIN
declare @max int
set @max=@a
if @max<@b
set @max=@b
if @max<@c
set @max=@c
if @max<@d
set @max=@d
return @max
END
望采纳