日期:2014-05-19  浏览次数:20718 次

case when...then...请教
(CASE   WHEN   P.Payer   = '113001 '  
  THEN   SELECT   SUM(NVL(AcceptPrice,0))   FROM   IBS_T_BID_SURROGATE   AGT   WHERE   AGT.PROJECT_ID   =   P.PROJID
  ELSE
      SELECT   SUM(NVL(BC.ReceiveChargePrice,0))   FROM   IBS_T_BID_BIDCHARGE   BC
      WHERE   BC.PROJID   =   P.PROJID
  END
  )   AS   SER_AMOUNT,
上面是查询语句中的一段   但是有问题   报错缺少表达式   then后面可不可以是一个查询语句呢?

------解决方案--------------------
(CASE WHEN P.Payer = '113001 '
THEN (SELECT SUM(isnull(AcceptPrice,0)) FROM IBS_T_BID_SURROGATE AGT WHERE AGT.PROJECT_ID = P.PROJID)
ELSE
(SELECT SUM(isnull(BC.ReceiveChargePrice,0)) FROM IBS_T_BID_BIDCHARGE BC
WHERE BC.PROJID = P.PROJID)
END
) AS SER_AMOUNT,

------解决方案--------------------
--这样试下
(CASE WHEN P.Payer = '113001 '
THEN (SELECT SUM(NVL(AcceptPrice,0)) FROM IBS_T_BID_SURROGATE AGT WHERE AGT.PROJECT_ID = P.PROJID)
ELSE
(SELECT SUM(NVL(BC.ReceiveChargePrice,0)) FROM IBS_T_BID_BIDCHARGE BC
WHERE BC.PROJID = P.PROJID)
END
) AS SER_AMOUNT
------解决方案--------------------
(CASE WHEN P.Payer = '113001 '
THEN (SELECT SUM(isnull(AcceptPrice,0)) FROM IBS_T_BID_SURROGATE AGT WHERE AGT.PROJECT_ID = P.PROJID
ELSE
(SELECT SUM(isnull(BC.ReceiveChargePrice,0)) FROM IBS_T_BID_BIDCHARGE BC
WHERE BC.PROJID = P.PROJID
END
) AS SER_AMOUNT,
------解决方案--------------------
這樣改:then 後面可以跟sql語句的
不過要用括號括起來


(CASE WHEN P.Payer = '113001 '
THEN (SELECT SUM(NVL(AcceptPrice,0)) FROM IBS_T_BID_SURROGATE AGT WHERE AGT.PROJECT_ID = P.PROJID)
ELSE
(SELECT SUM(NVL(BC.ReceiveChargePrice,0)) FROM IBS_T_BID_BIDCHARGE BC
WHERE BC.PROJID = P.PROJID)
END
) AS SER_AMOUNT,
上面是查询语句中的一段 但是有问题 报错缺少表达式 then后面可不可以是一个查询语句呢?