-1

Like the title, I want to find strings between two identical symbols, like

declare @str varchar(255);
set @str = 'I want to + get + all results + out + between two + plus sign'

So the intricacy here is @str has many identical plus symbols, and I just want to take out the string all results.

How should I do that with T-SQL?

Andrea
  • 11,801
  • 17
  • 65
  • 72
Larry Ding
  • 82
  • 2
  • 8
  • 1
    What version of SQL do you have? 2016 and Azure have this as a native function: https://learn.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql – AaronLS Jun 08 '17 at 17:41
  • Hello, thanks for letting me know but unfortunately I am using SQL server 2012 – Larry Ding Jun 08 '17 at 18:36
  • 2
    Possible duplicate of [How do I split a string so I can access item x?](https://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x), though there are other potential candidates for duplicates. Replace `+` with `,` and it's the original classic. – Jeroen Mostert Jun 08 '17 at 18:41

1 Answers1

0

Sounds like you want to use Replace.

select replace(@str,'+','')

--I want to  get  all results  out  between two  plus sign

If every + sign has a space before and after and you want to clean the spaces up, put a space after the + sign

select replace(@str,'+ ','')

--I want to get all results out between two plus sign
Jason
  • 945
  • 1
  • 9
  • 17