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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -