Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL-更新不起作用?_Sql_Sql Server 2012 - Fatal编程技术网

SQL-更新不起作用?

SQL-更新不起作用?,sql,sql-server-2012,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\u AccountTypeIdName=”Member'更改为“Existing”,而不管“new\u Existing=1还是0

当我运行这个查询时

UPDATE dbo.Account
SET new_AccountTypeIdName  =  IIF(new_Existing = 1 , 'Existing','Potential')
Where new_AccountTypeIdName = 'Member' 
AND new_Existing IN (0,1) 
它只是将任何“new\u AccountTypeIdName=”Member'更改为“Existing”,而不管“new\u Existing=1还是0”

谁能给我指出正确的方向吗? im使用sql server 2012

谢谢

尝试此查询

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) 

将查询拆分为两个简单的:

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

运行此命令:
SELECT*FROM Account,其中new\u AccountTypeIdName='Member'和new\u存在于(0,1)
中,以查看要更新的预期行。我怀疑会有空白结果。@i486,我运行了你的查询,得到了结果。我运行了你的查询,结果是相同的,它只说它影响了一行,但所有带有Farmer的行都受到了影响?然后检查你的数据和条件。这段代码可以解决OP的问题,几句话的解释将大大有助于让每个人都更容易理解这个答案。同样的结果?当我在CRM Online上查看“相同的结果”——即只有一个查询有效?