当我运行此查询时;
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
由于
答案 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)