sql - how to pick string basing on ID wise -


i have table have values

create table values (id int,val varchar(40)) insert values (id,val)values (1,'chemicals(sulphur4123)'),(2,'chemicals(sulphur4123)/raw') 

how can result set of :

id  val 1   sulphur4123 2   sulphur4123/raw 

so far have tried no luck

my code

select substring(val,0,charindex('/',val))+ right(val,4) values 

   declare @t table (id int,value varchar(40))    insert @t (id,value)values (1,'chemicals(sulphur4123)'),(2,'chemicals(sulphur4123)/raw')     select  substring(value,    charindex('(',value) + 1,     charindex(')',value) - charindex('(',value) - 1)+    +reverse(substring(reverse(value),1,charindex('/',reverse(value))))    result @t 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -