您可以創建這個功能
CREATE FUNCTION [dbo].[SplitString]
(
@sString nvarchar(2048),
@cDelimiter nchar(3),
@mark nchar(1)
)
RETURNS @tParts TABLE (part nvarchar(2048))
AS
BEGIN
if @sString is null return
declare @iStart int,
@iPos int
if substring(@sString, 1, 1) = @cDelimiter
begin
set @iStart = 2
insert into @tParts
values(null)
end
else
set @iStart = 1
while 1=1
begin
set @iPos = charindex(@cDelimiter, @sString, @iStart)
if @iPos = 0
set @iPos = len(@sString)+1
if @iPos - @iStart > 0
insert into @tParts
values (replace(ltrim(substring(@sString, @iStart, @iPos-
@iStart)) + @mark,'""','"'))
set @iStart = @iPos+1
if @iStart > len(@sString)
break
end
RETURN
END
GO
而且使用這種方式
SELECT * FROM [dbo].[SplitString]
('"3 LOW" "5 HIGH" "7 HIGH" "8 HIGH"','" "', '"')
結果
"3 LOW"
"5 HIGH"
"7 HIGH"
"8 HIGH"