sql server - search for a matching string using part of the string in SQL -


i current have 1 table whereby unique index of 'col_0' have same set of data 2 different indexes. problem copy function in application automatically cuts of description , adds "copied @ end".

example

col_0 description
annoying application problem
b annoy (copied column a)

i wanted search , update b matches i've tried join part of description.

so far i've tried charindex can't quite right.

i read request thus: "copied column a)" means copied description of record col_0 = 'a'. , want update "copied .." descriptions original description.

in order find "copied .." records using like. extract col_0 value string using string functions (mainly reverse + charindex find last occurrence of blank , substring extraction).

update mytable upd set description = (  select description  mytable orig  orig.col_0 =     substring(upd.description,               len(upd.description) - charindex(' ', reverse(upd.description)) + 2,               charindex(' ', reverse(upd.description) - 2             ) ) description '%(copied column %)'; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -