SQL if语句

时间:2011-04-04 22:09:57

标签: sql

我希望能写下来:

IF PROV_ID = PROVIDER NOT ON FILE or blank then use BILLING_PROV 
ELSE USE PROV_ID

Billing_prov是列名,所以我想返回该值。

2 个答案:

答案 0 :(得分:6)

SELECT
 CASE WHEN (PROV_ID = [PROVIDER NOT ON FILE or blank])
      THEN BILLING_PROV 
      ELSE PROV_ID
      END
FROM
 ...

答案 1 :(得分:2)

我假设“不存档或空白”表示空

SELECT COALESCE(PROV_ID, BILLING_PROV) as Whatever
FROM ...