Sql server SQL Server:如果两列具有特定值,则返回第三列

Sql server SQL Server:如果两列具有特定值,则返回第三列,sql-server,Sql Server,我正在尝试创建一个SQL查询,它执行以下操作 If (field-A = Value1) and (field-B = value1) then (field-c) 因此,如果两列有某个值,我想返回第三列的值。尝试以下方法: case when field-A = @value1 and field-B = @value1 then field-C else 'whatever else you want' end 试试这个: case when field-A = @va

我正在尝试创建一个SQL查询,它执行以下操作

If (field-A = Value1) and (field-B = value1)
then (field-c)
因此,如果两列有某个值,我想返回第三列的值。

尝试以下方法:

case 
  when field-A = @value1 and field-B = @value1 then field-C 
  else 'whatever else you want' end
试试这个:

case 
  when field-A = @value1 and field-B = @value1 then field-C 
  else 'whatever else you want' end

从fielda='value1'和fieldb='value2'所在的表中选择fieldc
从fielda='value1'和fieldb='value2'所在的表中选择fieldc

如果两个字段与所需的值不匹配,您应该更具体地了解所需的内容,因为可能出现各种情况。例如,您可以返回一些默认值(如
NULL
),也可以完全放弃该行。如果两个字段与所需值不匹配,您应该更具体地说明所需内容,因为可能会出现各种情况。例如,可以返回一些默认值(如
NULL
),也可以完全放弃该行。