首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

case when.then.请问

2012-02-11 
case when...then...请教(CASEWHENP.Payer 113001THENSELECTSUM(NVL(AcceptPrice,0))FROMIBS_T_BID_SURRO

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后面可不可以是一个查询语句呢?

热点排行