Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get SUM of some data in my table.

This is my query

SQL
Select paidCustomerCode,count(tblComparePods.hAWBNum) As hAWBNum,Sum(weight) As weight,SUM(Value) from tblOutboundHeader INNER JOIN tblComparePods ON tblOutboundHeader.hAWBNum=tblComparePods.hAWBNum  WHERE (Date>='2013/11/15' AND Date<='2013/11/30') AND tblComparePods.isconfirm ='0'Group by paidCustomerCode 


I Want to add this flowing query for this Function SUM(Value)  

CASE WHEN [ChageValue] = 0 THEN [Value] ELSE [ChageValue] END AS [Value](combine two columns in one table)


Any one can help me??
Posted
Updated 1-Dec-13 18:55pm
v8
Comments
[no name] 2-Dec-13 0:24am    
plz Any one can help me??

1 solution

Try replacing SUM(Value) with SUM(COALESCE(nullif(ChageValue,0),value))

SQL
Select paidCustomerCode,count(tblComparePods.hAWBNum) As hAWBNum,Sum(weight) As weight,SUM(COALESCE(nullif(ChageValue,0),value)) from tblOutboundHeader INNER JOIN tblComparePods ON tblOutboundHeader.hAWBNum=tblComparePods.hAWBNum  WHERE (Date>='2013/11/15' AND Date<='2013/11/30') AND tblComparePods.isconfirm ='0' AND paidCustomerCode= '0001' Group by paidCustomerCode 


Note: I have not tested with sample data just checked for syntax errors. NULLIF is available only from 2005 onwards.
 
Share this answer
 
v3
Comments
[no name] 2-Dec-13 0:42am    
i try Not working dear
ArunRajendra 2-Dec-13 0:51am    
Not working in the sense no correct result or error?
[no name] 2-Dec-13 1:00am    
error (Incorrect syntax near the keyword 'COALESCE'.
)
ArunRajendra 2-Dec-13 1:04am    
Ok try the full query I have posted in the solution.
[no name] 2-Dec-13 1:08am    
tnx a lot

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