954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

UPDATE from another table - Need help!

i want try to update the value of record from table1 where the value i need is from table2
like:

table1

Item_id | Quantity
0001    | 100
0002    | 200
0003    | 300
table2
Item_id | Quantity
0002    | 100
0003    | 50
when the query run.... i want the table1 shows
Item_id  | Quantity
0001     | 100
0002     | 300
0003     | 350


i tried every kind of way to do it...
but still can run it...

legend_89757
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

what exactly you tried ?

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

i tried to INNER JOIN the 2 table with added table1 quantity and table2 quantity,
then i tried to replace the added value to table1 quantity with UPDATE...
but it doesn't work

legend_89757
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

post your code here, will try to fix that.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

r u saying the below kind of query is not working??

update t1
set t1.Quantity = t1.Quantity + t2.Quantity
from table1 t1
inner join table2 t2
on t1.Item_id = t2.Item_id

tessy7
Junior Poster in Training
51 posts since Apr 2008
Reputation Points: 15
Solved Threads: 3
 

make a cursor and then select rows from table2 and then update one by one rows in table1

crishlay
Junior Poster
132 posts since May 2010
Reputation Points: 10
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: