SQL - UPDATE不起作用?

时间:2015-08-21 09:52:48

标签: sql sql-server-2012

当我运行此查询时;

UPDATE dbo.Account
SET new_AccountTypeIdName  =  IIF(new_Existing = 1 , 'Existing','Potential')
Where new_AccountTypeIdName = 'Member' 
AND new_Existing IN (0,1) 

它只是将'new_AccountTypeIdName ='Member'更改为'Existing',无论'new_existing = 1还是0'。

有人能指出我正确的方向吗? 即时通讯使用sql server 2012

由于

2 个答案:

答案 0 :(得分:1)

将您的查询拆分为2个简单:

UPDATE dbo.Account
  SET new_AccountTypeIdName  =  'Existing'
    Where new_AccountTypeIdName = 'Member' AND new_Existing = 1

UPDATE dbo.Account
  SET new_AccountTypeIdName  =  'Potential'
    Where new_AccountTypeIdName = 'Member' AND new_Existing = 0

答案 1 :(得分:0)

尝试此查询

UPDATE dbo.Account
SET new_AccountTypeIdName  =  case when new_Existing = 1 then 'Existing' else 'Potential' end
Where new_AccountTypeIdName = 'Member' 
AND new_Existing IN (0,1)