How to update a column only when last word of string matches a letter

梦想与她 提交于 2019-12-13 03:06:40

问题


I want to update columns(HostActvTyp and HostPrvTyp) when (HostCd) column last name is matching with last word of the string is "R" example string for host column "NXVR','REACTIVE', so the last word is R so we have to update to Reactive when it's N' to 'NEW' example "XVDN" enter image description here


回答1:


seems you are looking for left or substr()

update tablename 
set ActTyp = 'INDEPENDENT' 
where ActvTyp = left(your_value,1 )



回答2:


https://www.db-fiddle.com/f/bG4jZfnWksjc315eGTuG2k/1

UPDATE tablename 
SET ActTyp = 'INDEPENDENT' 
WHERE 'I' = RIGHT(ActvTyp, 1)

Or if there is a space separator

UPDATE tablename 
SET ActTyp = 'INDEPENDENT' 
WHERE ' I' = RIGHT(ActvTyp, 2)


来源:https://stackoverflow.com/questions/55907953/how-to-update-a-column-only-when-last-word-of-string-matches-a-letter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!