Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,i have id - name - country - purchase value - shipping value - other charge -Total
22 1111
5 20
10


as u can see i want to sum between those columns and display it into total column but maybe column will be null empty not should have all 3 column full how can i do this <b



thank u....

What I have tried:

SELECT Id,Name,Country,purchesvalue+shippingvalue+othercharge as Total
From test;
SELECT Id,Name,Country,purchesvalue+shippingvalue as Total
FROM test



this just overwrite the query so is there any method to make it simple


and i try this this told me syntax error
SELECT  (Id,Name,Country,ISNULL(purchesvalue,0) + ISNULL(shippingvalue,0) + ISNULL(shippingvalue,0)) as 'Total'
FROM test
Posted
Updated 21-Mar-17 1:41am
v3

Try:
SQL
SELECT Id, Name, Country, ISNULL(purchesvalue, 0) + ISNULL(shippingvalue, 0) + ISNULL(shippingvalue, 0)) as [Total]
   
Your later query seems correct. Try this

SELECT  Id,Name,Country,ISNULL(purchesvalue,0) + ISNULL(shippingvalue,0) + ISNULL(shippingvalue,0) as 'Total'
FROM test


A better approach is to have a VIEW that hide all above sums complexity and make query more readable.
   
Comments
Member 13044689 21-Mar-17 7:10am
   
thank u sir
SELECT Id,Name,IsNULL(p_value,0) + IsNULL(s_vale,0) + IsNULL(o_value,0) as 'Total'
FROM product

Try this works for me.
   

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