将字符串根据特定分隔符输出为字典/数组/表格
ALTER FUNCTION [dbo].[StringToDic](@input varchar(max),@delimiter_r varchar(max),@delimiter_c varchar(max)) RETURNS @t TABLE(OKey varchar(max),OValue varchar(max)) AS BEGIN -- Fill the table variable with the rows for your result set DECLARE @k varchar(max) WHILE CHARINDEX(@delimiter_r,@input)>0 BEGIN SELECT @k=LEFT(@input,CHARINDEX(@delimiter_r,@input)-1) INSERT INTO @t(OKey) SELECT @k UPDATE @t SET OKey=LEFT(@k,CHARINDEX(@delimiter_c,@k)-1),OValue=RIGHT(@k,LEN(@k)-CHARINDEX(@delimiter_c,@k)) WHERE OKey=@k SELECT @input=RIGHT(@input,LEN(@input)-CHARINDEX(@delimiter_r,@input)) END SELECT @k=@input INSERT INTO @t(OKey) SELECT @k UPDATE @t SET OKey=LEFT(@k,CHARINDEX(@delimiter_c,@k)-1),OValue=RIGHT(@k,LEN(@k)-CHARINDEX(@delimiter_c,@k)) WHERE OKey=@k RETURN END