如何计算存储过程中的列?

时间:2015-03-07 12:22:23

标签: sql

我有一个这样的存储过程:

 SELECT DISTINCT 
     C.cid
     , C.custclientid
     , C.client
     , C.company
     , C.product
     , C.producttakendate
     , C.total 
     , P.reciveamt
     , P.dueamt
     , (SELECT TOP 1 rcvdate 
        FROM paymentdata AS PD1 
        WHERE PD1.pclientid = PD.pclientid 
          AND PD1.productname = PD.productname 
        ORDER BY rcvdate DESC) AS rcvdate
     , (SELECT TOP 1 nxtdate 
        FROM paymentdata AS PD1 
        WHERE PD1.pclientid = PD.pclientid 
          AND PD1.productname = PD.productname 
        ORDER BY rcvdate DESC) AS nxtdate
     , (SELECT TOP 1 notepayment 
        FROM paymentdata AS PD1 
        WHERE PD1.pclientid = PD.pclientid 
          AND PD1.productname = PD.productname 
        ORDER BY rcvdate DESC) AS notepayment
FROM
    customermaintenance C 
LEFT OUTER JOIN 
    payment P ON C.custclientid = P.pclientid
LEFT OUTER JOIN 
    paymentdata PD ON P.pclientid = PD.pclientid
WHERE
    C.custclientid = 1 AND C.product = 'Software'
  • c.total有5000
  • p.reciveamt有NULL
  • p.dueamt有NULL

我有datalist,有

<asp:Label ID="nextamountLabel" runat="server" Text='<%# Eval("dueamt") %>' />

我想放出dueamt = 5000

然后我在这个程序中如何计算?

1 个答案:

答案 0 :(得分:2)

C.Total - COALESCE(p.reciveamt,0)

COALESCE在其参数

中返回它遇到的第一个非null