May I know how to use SQL select query to make new line after character ("|") ?
Asked
Active
Viewed 187 times
-1
-
I'd guess a recursive cte (WITH) can be used. – jarlh Feb 02 '21 at 08:11
-
I think you want something like this: https://stackoverflow.com/questions/14328621/splitting-string-into-multiple-rows-in-oracle – Koen Lostrie Feb 02 '21 at 09:58
3 Answers
0

Popeye
- 35,427
- 4
- 10
- 31
-
Hi, i tried use replace but not successful due to after "|" is next record, i thinking use join could be can solve this, but i no idea how to use join query ? – Hoong wai kong Feb 02 '21 at 06:45
0
If you mean new line in SQL you can try it
DECLARE @NewLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
PRINT ('SELECT FirstLine AS MyFirstLine ' + @NewLineChar + 'SELECT SecondLine AS MySecondLine')
0
you can also this table-value function. you can set your entire text into function as well as a delimiter that is "|" in your case, finally it return multiple records based on how many "|" was exist.
ALTER FUNCTION [dbo].[Split] ( @string NVARCHAR(MAX), @delimiter CHAR(1)) RETURNS @output TABLE(splitdata NVARCHAR(MAX))
BEGIN
DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
WHILE @start < LEN(@string) + 1 BEGIN
IF @end = 0
SET @end = LEN(@string) + 1
INSERT INTO @output (splitdata)
VALUES(SUBSTRING(@string, @start, @end - @start))
SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)
END
RETURN
END
If your problem wont solve feel free to ask again.
RaminHbb

Ramin Hbb
- 9
- 2