Break string Into multiple lines in SQL Server
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',' ')
精彩评论