如果前两个字符为零,我将如何替换它们?
示例:
1. 00001
2. 00123
3. 02451
应该是:
1. 11001
2. 11123
3. 02451
编辑:忘记提及我在选择子句中需要这个(在 View 中) 谢谢。
最佳答案
update YourTable
set col1 = '11' + substring(col1, 3, len(col1)-2)
where col1 like '00%'
在 View 中,您可以这样做:
select case
when col1 like '00%' then stuff(col1, 1, 2, '11')
else col1
end
from YourTable;
关于sql - 替换字符串中的前导字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14216823/