I want to split a string in this format Quote:
\"date=10/10/2000|age=13^date=01/01/2001|age=12^date=02/02/2005|age=8\"
. Actually this stri
DECLARE @s VARCHAR(300)
SET @s = 'RELGENINS|1121232243434|343434343434|343434-683211|34343434.00|CIT|22297568|NA|INR|ONDIRECT|NA|NA|NA|22-03-2014 10:43:20|0300|NA|NA|NA|NA|NA|NA|NA|NA|NA|Success|1790153891'
DECLARE @tmp TABLE( aDate varchar(50))
;WITH MyRows AS
(
SELECT LEFT(@s, CHARINDEX('|', @s) -1) AS MyRow, RIGHT(@s, LEN(@s) - CHARINDEX('|', @s)) AS Remainder
UNION ALL
SELECT LEFT(Remainder, CHARINDEX('|', Remainder) -1) AS MyRow, RIGHT(Remainder, LEN(Remainder) - CHARINDEX('|', Remainder)) AS Remainder
FROM MyRows
WHERE CHARINDEX('|', Remainder)>0
UNION ALL
SELECT Remainder AS MyRow, NULL AS Remainder
FROM MyRows
WHERE CHARINDEX('|', Remainder)=0
)
INSERT INTO @tmp (aDate)
SELECT SUBSTRING(MyRow, 0, 20) as date
FROM MyRows
SELECT *
FROM @tmp