我是SQL Server的初学者,我在表格列中有这个值:
98123456789
54782012
如果'98'为真,我想写一个查询来查找第一个字符串然后从第一个字符串中删除它,例如up this this:
98123456789 ----> starts with 98 start then clear that result ====> 123456789
54782012 ----> does not start with 98 then not clear that result ===> 54782012
如何为此目的编写查询?
答案 0 :(得分:1)
UPDATE [Table] SET Column=
CASE LEFT(Column, 2)
WHEN '98' THEN RIGHT(Column,3)
ELSE Column
END
如果您的列是整数类型,请将RIGHT...
替换为CAST(RIGHT(Column,3) as int)
答案 1 :(得分:0)
试试这个
UPDATE TAB SET COL1= CASE WHEN COL1 LIKE '98%' THEN SUBSTRING(COL1, 3,LEN(COL1))
ELSE COL1 END FROM TAB