how to find words between two words in a string


hi

how find words  between 2 words in string in sql

eg 1 word "users" , second word " name1 " in given string

how find "test" in given string

i tried this

declare @str varchar(max)
set @str='dear  afolabi dare fatai  1 of our users test name1 looking cyber description : dsfs.'
select substring (@str,5,9)

 

thanks in advance

try this

declare @str varchar(max)
set @str='dear  afolabi dare fatai  1 of our users test name1 looking cyber description : dsfs.'
select ltrim(rtrim(substring(@str , charindex('users',@str) +len('users'),charindex('name1',@str) - (charindex('users',@str) +len('users')) ) ))

 


http://uk.linkedin.com/in/ramjaddu


SQL Server  >  Getting started with SQL Server



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........