Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables,itemmaster and stockdetails as follows:
itemmaster:
C#
itemid  availableqty
100        0
101        0
102        0
103        0
104        0
105        0

stockdetails:
C#
itemid   availabelqty  branch
101  	    20  	 1
101 	    30	         2
101         30  	 3
102         90           1
102         80           2
102         20           3
102         30           4
103         40           1
103         30           4
103         50           2
103         70  	 3

i want to update itemmaster table from sum of all stockdetails table availabelqty...

Have any single quries to update that table data's?
after the execution of queries the itemmaste table should be updated like this
C#
itemid  availableqty
100     0
101	80
102	220
103	190
104	0
105	0

i tried this using this query
SQL
update tblitemmaster set availableqty=(select sum(availableqty) from stockdetails where itemid =110)
where ItemID =102


but this is updating at time only one record.I want to update all record.Have any quries to update that table?

Any one please help me.
Posted
Updated 22-Sep-13 21:49pm
v3

1 solution

Try something like this:
SQL
UPDATE t1
    SET t1.avaliblequality = t2.avaliblequality
FROM itemmaster AS t1 INNER JOIN (
    SELECT itemid, SUM(avaliblequality) AS avaliblequality
    FROM stockdetails
    GROUP BY itemid
    ) AS t2 ON t1.itemid = t2.itemid
 
Share this answer
 
Comments
Maciej Los 23-Sep-13 4:20am    
Please, mark my answer as a solution (green button) to remove your question from "unanswered list".
hebsiboy 23-Sep-13 4:31am    
Thank you........\\
It is working fine..
Maciej Los 23-Sep-13 4:37am    
Thank you and you're welcome ;)

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