Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select SUM(item_store.quantity) -  (select SUM(transaction_items_store.quantity) AS exp2  from  transaction_items_store 
                              where  transaction_items_store.item_no=item_store.item_no) as Q
                              FROM item_store 
                              group by   item_store.item_no




===========the output is =======
VB
4
10
7
NULL
NULL
Posted
Comments
Kschuler 18-Oct-13 13:49pm    
What is your question? Can you explain more? Tell us what the code is currently doing and what you WANT it to do. Tell us if you are getting an error message and what the exact error message is.
jumah 18-Oct-13 14:09pm    
there is no error with the code...i have 2 tables(item_store and transaction_items_store) evrey one hase a quantity column i want to subtract the 2 coulmns but if the Column of table 2 hase no value it return null value as shown in my output
example
item_store transaction_items_store q
20 16 4
11 10 10
12 5 7
8 null null
7 null null

i want the result to be
4
10
7
8
7

It sounds like your real question is "How can I select a null value as a zero[^]?"

The actual syntax will depend on what actual database you are using. This google result[^] has a couple of options for some different databases.

Hope this helps.
 
Share this answer
 
Comments
jumah 18-Oct-13 14:53pm    
Many thanks it is solved.....
SQL
select SUM(item_store.quantity) -
  (select IFNULL(SUM(transaction_items_store.quantity),0) AS exp2  from  transaction_items_store
                              where  transaction_items_store.item_no=item_store.item_no) as Q
                              FROM item_store
                              group by   item_store.item_no
 
Share this answer
 

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