有一字符串 "2003,2004,2005,2006,2007 "如何用sql显示最大值
------解决方案--------------------
declare @s varchar(100),@ss varchar(10),@sss varchar(10)
select @s = '2003,2004,2005,2006,2007 '+ ', '
select @ss = substring(@s,1,charindex( ', ',@s)-1),@s = stuff(@s,1,charindex( ', ',@s), ' '),@sss= ' '
while len(@s)> 0 begin
select @sss = substring(@s,1,charindex( ', ',@s)-1),@s = stuff(@s,1,charindex( ', ',@s), ' ')
if isnumeric(@sss) =1
if @ss < @sss
set @ss = @sss
end;
select [email protected]