sql - trim the column value string -


in sql query, need values below using select query of column. result has text after first space ' ' , before first '('

source column

create table test_table (column1 varchar(50)) insert test_table values ('0636 kavithi (loc)'), ('0638 sri krishna (nat)'), ('0639 selvam'), ('0643 service (loc)'), ('0644 fina care event (loc)') 

i need string found between first ' ' , '('

expected result

kavithi sri krishna selvam service fina care event 

another approach without using outer apply.

select case when column1 '%(%'              substring(right(column1,len(column1)-charindex(' ',column1)),0,                  charindex('(',right(column1,len(column1)-charindex(' ',column1)),0))              else right(column1,len(column1)-charindex(' ',column1))              end trimmed test_table 

output

trimmed kavithi sri krishna selvam service fina care event 

sql fiddle: http://sqlfiddle.com/#!3/69dd1/20/0


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -