SQL SERVER 2008 - Returning a portion of text using SUBSTRING AND CHARINDEX. Need to return all text UNTIL a specific char -


i have column called 'response' contains lots of data person.

i'd return info after specific string

but, using method below (when people have <100 iq) | comes directly after required number..

i'd characters after the'personiq=' before pipe.

i'm not sure of best way achieve this.

query speed concern , idea of nested case not best solution.

any advice appreciated. thanks

substring(response,(charindex('personiq=',response)+9),3) 

this suggestion:

declare @s varchar(200) = 'aaa=bbb|cc=d|personiq=99|e=f|1=2' declare @iq varchar(10) = 'personiq=' declare @pipe varchar(1) = '|'  select substring(@s,          charindex(@iq, @s) + len(@iq),          charindex(@pipe, @s, charindex(@iq, @s)) - (charindex(@iq, @s) + len(@iq))          ) 

instead of 3 in formula should calculate space between @iq , @pipe last part of formula charindex(@pipe, @s, charindex(@iq, @s)) - (charindex(@iq, @s) + len(@iq)), gets first @pipe index after @iq, , substructs index of iq value.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -