How to extract substring in SQL Server -


i have field okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos

i'd extract name = value data.

how can using sql server 2008 in efficient way? thank you

try this

; mytable (     select 'okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos' fullstring     union      select 'fkgbokfgbo&name=fokdofkd&okfaos' fullstring     union      select 'okbogkbogkbokgbok' fullstring ), patternindex (     select          fullstring + '&' fullstring,          charindex ('&name=', fullstring) + 1 locationofequalsign,          charindex ('&', fullstring, charindex ('&name=', fullstring)+1) nextbreak     mytable ), splitnamevalue (     select          fullstring,          case              when nextbreak <> 0              substring (fullstring, locationofequalsign, nextbreak-locationofequalsign)              else '' end         namevaluepair     patternindex ) select *  splitnamevalue 

returns

fullstring                                                namevaluepair --------------------------------------------------------- --------------------------------------------------------- fkgbokfgbo&name=fokdofkd&okfaos                           name=fokdofkd okbogkbogkbokgbok                                          okbogkbogkbokgbokgobkgobkofkgbokfgbo&name=fokdofkd&okfaos name=fokdofkd  (3 row(s) affected) 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -