2017-08-04 108 views
-4

我想为我的邮编的最后4位数使用填充。在SQL Server中填充

EX。如果我的邮编是12345999,那么我想用6789替换9999

如果在最后四个位置没有9999,则不需要替换。

+2

你真的应该做出一些努力和尝试搜索在互联网上回答第一。请参阅https://docs.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql和https://docs.microsoft.com/en-us/sql/t-sql/functions/patindex-transact-sql – Alex

+0

你有试过什么吗? – Rokuto

回答

1

你可以使用替代

SELECT REPLACE(your_column, '9999', '6789') 
from your_table 
where RIGHT(your_column,4) ='9999'; 

或更新

Update your_table 
set your_column = REPLACE(your_column, '9999', '6789') 
where RIGHT(your_column,4) ='9999';