SQL分割字符串函数
时间:2021-07-01 10:21:17
帮助过:3人阅读
FUNCTION [dbo].
[fun_splitstr](
@str VARCHAR(
MAX))
RETURNS @temp TABLE(id
INT)
AS
BEGIN
DECLARE @ch AS VARCHAR(
100)
SET @str+=‘,‘
WHILE(
@str<>‘‘)
BEGIN
SET @ch = LEFT(
@str,
CHARINDEX(
‘,‘,
@str,
1)
-1)
IF @ch>0
INSERT @temp VALUES(
@ch)
SET @str=STUFF(
@str,
1,
CHARINDEX(
‘,‘,
@str,
1),
‘‘)
END
RETURN
END
SQL分割字符串函数
标签: