Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

SQL Update 1 tables columns from a different tables columns

Looking for some help with trying to write a stored procedure that will update 2 columns with values from another tables columns. I have a table that holds inventory items for both wherehouse locations. A user needs to look at what is in Wherehouse A and then builds a list of items that are needed at Wherehouse B. Once the user has done this an order is generated to be filled and shipped out. When wherehouse B recieves the order they check the qty and then updates the transfer request saying whether or not all items were received. My problem now is that I am needing to update the inventory table to show that items from wherehouse A are now in stock in wherehouse B.
I have no problems updating the transfer table when the items are recieved but now I have a problem updating the inventory table to show updated qtys and that the location has changed. What is the best way to do this?
0
digital_slavery
Asked:
digital_slavery
  • 2
1 Solution
 
imitchieCommented:
update a
set col1 = b.col1, col2 = b.col2
from WarehouseATbl a
 inner join WarehouseBTbl b on ... condition
0
 
imitchieCommented:
can you describe what sort of tables and fields you have, and what sort of procedure you are after? i.e.

inventory: location, stockcode, current_qty
sp: input - locationfrom, locationto, stockcode, qty

something like

create procedure stockmoved (  @locationfrom int, @locationto int, @stockcode int, @qty int )
as
update inventory set qty = qty - @qty where locationid = @locationfrom and stockcode = @stockcode
update inventory set qty = qty + @qty where locationid = @locationto and stockcode = @stockcode
0
 
Computer101Commented:
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now