Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-01-15 : 14:50:52
|
| Working with one table IMINVLOC which holds inventory qty's and locations. What I would like to do is take all of the qty's from location 2 and add them to location 1. All location 2 records have a location 1 record. Table would look something like this:item_no loc QOH abc 1 500 abc 2 400My goal is to update abc's loc 1 to 900 for QOHNot quite sure how to do this?? |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-01-15 : 15:09:40
|
| Tried something like this but Get a message that I must declare my variable on line 22.begindeclare @imlocation table (item_no char (15) not null,loc char (3) not null,Qty_on_hand decimal (9) not null,rownum int IDENTITY(1,1) pRIMARY KEY NOT NULL)insert into @imlocationselect item_no, loc, Qty_on_handfrom iminvloc_sqlwhere loc ='2'UPDATE iminvloc_sqlSET iminvloc_sql.qty_on_hand = @imlocation.qty_on_hand + iminvloc_sql.qty_on_handjoin @imlocation on @imlocation.item_no = iminvloc_sql.item_nowhere iminvloc_sql.loc = '1' |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2009-01-15 : 15:16:07
|
| [code]update aset QOH = b.QOHfrom IMINVLOC a inner join IMINVLOC bon a.item_no = b.item_noand a.loc > b.loc[/code] |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-01-15 : 15:22:31
|
| That looks like its just updating qoh form location 2 to 1. I want to ADD the QoH from location 2 to location 1. |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2009-01-15 : 15:31:06
|
| [code]update aset QOH = case when a.loc = 1 then a.QOH+b.QOHwhen a.loc = 2 then b.QOH endfrom IMINVLOC a inner join IMINVLOC bon a.item_no = b.item_noand a.loc <> b.loc[/code] |
 |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2009-01-15 : 15:48:35
|
| That seemed to do the trick.Thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-15 : 23:01:01
|
| [code]update aset a.QOH = a.QOH+b.QOHfrom IMINVLOC a inner join IMINVLOC bon a.item_no = b.item_noand a.loc =1and b.loc=2[/code] |
 |
|
|
|
|
|