How to update a column only when last word of stri

2019-08-17 15:14发布

问题:

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)