开发者

Break string Into multiple lines in SQL Server

开发者 https://www.devze.com 2023-04-04 20:27 出处:网络
I have a string stored in SQL Server with multiple lines. How I can sel开发者_开发技巧ect from SQL Server with multiline?

I have a string stored in SQL Server with multiple lines.

How I can sel开发者_开发技巧ect from SQL Server with multiline?

ForEx: data stored as Line1 Line2 Line3

How I can display

Line1 <nextLine>
Line2 <nextline>
Line3


CREATE FUNCTION dbo.fStringToTable(@P_KeyWordList AS Varchar(max),@Delimeter as varchar(1) )
RETURNS
@Result
TABLE(VarcharValue Varchar(255))
AS
BEGIN
DECLARE @V_Keyword VARCHAR(255),
@CIndex Int
IF(@P_KeyWordList is not null)
BEGIN
SET @CIndex = CHARINDEX(@Delimeter,@P_KeyWordList)
WHILE (@CIndex > 0 )
BEGIN
SET @V_Keyword = SUBSTRING(@P_KeyWordList,1,@CIndex-1)
SET @P_KeyWordList = SUBSTRING(@P_KeyWordList,@CIndex+1,LEN(@P_KeyWordList)-@CIndex)
INSERT INTO @Result values (@V_Keyword)
SET @CIndex = CHARINDEX(@Delimeter,@P_KeyWordList)
END
SET @V_Keyword = @P_KeyWordList
INSERT INTO @Result values (@V_Keyword)
END
RETURN
END
GO Select * from dbo.fStringToTable('l1 l2 l3',' ')

0

精彩评论

暂无评论...
验证码 换一张
取 消