Sql server 2012 具有多个条件的SQL Server案例
我试图找出如何在多个条件下执行SQLServer CASE命令 我正试图利用这些条件Sql server 2012 具有多个条件的SQL Server案例,sql-server-2012,Sql Server 2012,我试图找出如何在多个条件下执行SQLServer CASE命令 我正试图利用这些条件 If column_a = 'test' AND column_b IS NULL OR (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480 THEN 'OK' ELSE 'CHECK' END 所以我想说的是: If column_a = 'test' AND column_b IS NULL return 'OK' OR
If column_a = 'test' AND column_b IS NULL OR (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480 THEN 'OK'
ELSE 'CHECK'
END
所以我想说的是:
If column_a = 'test' AND column_b IS NULL return 'OK'
OR If column_a = 'test' AND (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480 THEN 'OK'
所以我为声明写的是
CASE WHEN column_a = 'test' AND column_b IS NULL OR (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480 THEN 'OK'
ELSE 'CHECK'
END
我没有得到任何错误,只是没有得到想要的结果。这是SQL Server中多个AND或语句的正确顺序吗?。我建议这样做:
CASE
WHEN column_a='test' AND column_b IS NULL
THEN 'OK'
WHEN column_a = 'test' AND (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480
THEN 'OK'
ELSE 'CHECK'
END
我会把它分解得有点不同。我建议这样做:
CASE
WHEN column_a='test' AND column_b IS NULL
THEN 'OK'
WHEN column_a = 'test' AND (column_b IS NOT NULL AND Column_c = Column_d) OR Column_e >= 480
THEN 'OK'
ELSE 'CHECK'
END
试试这个:
case
when column_a = 'test'
and (column_b is null
or
(column_b is not null and column_c = column_d))
or column_e >=480
then 'OK'
或者显示一些样本数据和预期结果,以便我们更好地了解其作用尝试以下方法:
case
when column_a = 'test'
and (column_b is null
or
(column_b is not null and column_c = column_d))
or column_e >=480
then 'OK'
或者展示一些样本数据和预期结果,这样我们就可以更好地了解它的作用谢谢dbajr-我试过了,它对我有效。非常感谢。谢谢。我试过了,它对我有用。非常感谢你的建议非常有用非常感谢你的建议非常有用非常感谢