调用这个方式时输入参数(1,2,3,4,5),返回结果
Id
1
2
3
4
5
CREATE
FUNCTION
convertCharToMultiRows(
@convertString
varchar
(
8000
),
@strSeprate
varchar
(
10
))
RETURNS
@temp
TABLE
(Id
int
)
AS
BEGIN
DECLARE
@i
int
SET
@convertString
=
rtrim
(
ltrim
(
@convertString
))
SET
@i
=
charindex
(
@StrSeprate
,
@convertString
)
WHILE
@i
>=
1
BEGIN
INSERT
@temp
VALUES
(
LEFT
(
@convertString
,
@i
-
1
))
SET
@convertString
=
substring
(
@convertString
,
@i
+
1
,
len
(
@convertString
)
-
@i
)
SET
@i
=
charindex
(
@StrSeprate
,
@convertString
)
END
IF
@convertString
<>
'
\
'
INSERT
@temp
VALUES
(
CONVERT
(
int
,
@convertString
))
RETURN
END