1
Reply

Write a SQL Function to find the MAX and MIN number From String .

    declare @input varchar(100) declare @max int declare @min int declare @num int declare @counter int set @counter=1 set @input='20,402,32,5,0,-7,1158,55,99,-9,' --select charindex(',',@input),left(@input,charindex(',',@input)),len(@input),right(@input,len(@input)-charindex(',',@input)) while (len(@input)>0) begin set @num=left(@input,charindex(',',@input)-1) set @input = right(@input,len(@input)-charindex(',',@input))--print len(@input) if @counter=1beginset @max=@numset @min=@numend elsebeginif @max<@numset @max=@numif @min>@numset @min=@numendset @counter=@counter+1 endprint @max print @min