2017-08-04 76 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';