I have the following Text:
"Original ----- The cow jumped over the moon ----- 20200723 --NEW-- The cow jumped over the sun ----- "
I'm trying to write a t-sql query that will extract everything between the string "Original ----- " and the following " ----- ", so my outcome would be:
"Original ----- The cow jumped over the moon ----- "
I've tried writing something like this:
declare @Text nvarchar(max) = 'Original ----- The cow jumped over the moon ----- 20200723 --NEW-- The cow jumped over the sun ----- '
select SUBSTRING(@Text, CHARINDEX('Original ----- ', @Text)
, CHARINDEX(' ----- ',@Text) - CHARINDEX('Original ----- ', @Text) + Len(' ----- '))
But it just returns Original -----.
Please help!
CHARINDEX(' ----- ',@Text) - CHARINDEX('Original ----- ', @Text)finds the same occurrence of' ----- 'twice.