當前位置:成語大全網 - 書法字典 - Sql查詢問題,如何把分號分隔的數據壹個壹個拿出來?

Sql查詢問題,如何把分號分隔的數據壹個壹個拿出來?

- SELECT * FROM dbo。FunSplitStringToAraay( '28,353,2,35,88 ',',')

創建函數dbo。FunSplitStringToAraay(@ vch string varchar(1000),@vchSplit varchar(10))

返回@tabArray表

字符串varchar(100)

)

如同

開始

DECLARE @intStart int

DECLARE @intLocation int

DECLARE @ vchSubstring varchar(100)

SELECT @intStart =1

SELECT @ int location = CHARINDEX(@ vch split,@vchString,@intStart)

WHILE(@ int location & lt;& gt0 )

開始

SELECT @ vchSubstring = SUBSTRING(@ vchString,@intStart,@intLocation-@intStart)

INSERT INTO @ tab array(string)SELECT @ vch substring

SELECT @ int start = @ int location+1

SELECT @ int location = CHARINDEX(@ vch split,@vchString,@intStart)

結束

返回

結束