在數據庫裡自定議函數。
CREATE FUNCTION GetArrayData(@String varchar(8000),@SetCount int)
RETURNS VARCHAR(100) AS
begin
Declare @tmp VARCHAR(100), @Count INT, @GetLen INT, @Str VARCHAR(1)
SET @Str = ','
SET @String = @String + @Str + ' '
SET @Count = 0
SET @GetLen = 0
WHILE (LEN(@String) > 0) AND (@SetCount > 0) AND (LEN(@Str) > 0)
begin
SET @GetLen = CHARINDEX(@Str,@String)
Set @Count = @Count + 1
IF @Count = @SetCount
begin
SET @tmp =SUBSTRING(@String,1,@GetLen-1)
BREAK
END
SET @String = REPLACE(@String,SUBSTRING(@String,1,@GetLen),'')
END
Return @tmp
END
-- 對性能上的優化