2012-04-22 49 views
1

我想创建一个SQL查询,执行以下操作。SQL Server:如果2列有一个特定的值,然后返回第三列

If (field-A = Value1) and (field-B = value1) 
then (field-c) 

因此,如果2列有一定的值,我想返回第三列的值。

+0

你应该更具体,以你希望在什么情况下,这两个领域做*不*匹配所需的值,因为各种情况都是可能的。例如,你可以返回一些默认值(如'NULL'),或者你可以完全丢弃该行。 – 2012-04-23 00:24:18

回答

3

试试这个:

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

select fieldc from table where fielda='value1' and fieldb='value2'

相关问题