当Col A仅包含数字,Acol

时间:2019-04-25 11:45:40

标签: sql sql-server sql-server-2012

我有两个Col分别为A和B,当A col仅包含数字时,需要更新B col

仅当A包含数字Else出口时,我才必须更新col

我坚持使用它,下面是我的查询

Update set empID = New_EMP_id 
Where RegID = New_RegID AND (RegSeq = '%[^0-9]%' or RegSeq='' or RegSeq = 'NULL')

预先感谢

4 个答案:

答案 0 :(得分:1)

根据您的语法,我将假定您正在使用SQL Server。如果是这样:

update t
    set empID = @New_EMP_id 
where RegID = @New_RegID and
      (RegSeq not like '%[^0-9]%' or RegSeq is null);

答案 1 :(得分:1)

您可以使用TRY_CAST之类的

UPDATE table1 
SET empID = New_EMP_id 
WHERE RegID = New_RegID AND (ReqSeq IS NULL OR TRY_CAST(ReqSeq AS INT) IS NOT NULL)

答案 2 :(得分:0)

假设sql-server的版本大于或等于2008,请尝试执行此操作

Update set empID = New_EMP_id 
Where RegID = New_RegID and (isnumeric(RegSeq) = 1 or RegSeq='' or RegSeq = 'NULL')

答案 3 :(得分:0)

尝试一下:

Declare @t table ( a varchar (10),b varchar(10))

Insert into @t values ('TEST','TEST')
Insert into @t values ('ABC','1245A')
Insert into @t values ('ABC','1245')



Update a1 set a='Updated' 
from @t a1
where ISNUMERIC(b) = 1

select * from @t