How to update a column only when last word of stri

2019-08-17 15:27发布

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

2条回答
太酷不给撩
2楼-- · 2019-08-17 15:55

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)
查看更多
再贱就再见
3楼-- · 2019-08-17 16:07

seems you are looking for left or substr()

update tablename 
set ActTyp = 'INDEPENDENT' 
where ActvTyp = left(your_value,1 )
查看更多
登录 后发表回答