Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have store procedure following,

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 have 5000
p.reciveamt have NULL
p.dueamt have NULL
i have datalist, whic have

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

i want to out put dueamt=5000 then how i calculate in this procedure?
Posted
Updated 7-Mar-15 1:47am
v2
Comments
King Fisher 7-Mar-15 7:25am    
Whats your Question?
Karmesh_Madhavi 7-Mar-15 7:40am    
i want to calculate like( p.dueamt=c.total-p.reciveamt)
i try C.total-p.reciveamt as dueamt

but it get NULL. i want 0
King Fisher 7-Mar-15 7:49am    
can you show your Table Structure with Some Dummy Data ? So that we can help you

1 solution

The standard states that any operation involving NULL will yield NULL. As NULL is not zero - it is unavailable data. So if you deliberatelly want to treat NULL as zero in a special case, you have to do it manually. The simplest approach is using COALESCE(expression, 0).

In your case it will looke like this one:
SQL
COALESCE(c.total,0)-COALESCE(p.reciveamt,0)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900