Solved

SQL Update 1 tables columns from a different tables columns

Posted on 2007-11-28
4
201 Views
Last Modified: 2010-03-20
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
Comment
Question by:digital_slavery
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 500 total points
ID: 20372244
update a
set col1 = b.col1, col2 = b.col2
from WarehouseATbl a
 inner join WarehouseBTbl b on ... condition
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20372269
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
 
LVL 1

Expert Comment

by:Computer101
ID: 20953231
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best way to use SSMS intellisense when querying 5 61
How does this SELECT query work 11 102
SQL Query Syntax Join 4 34
Running Total in Access 4 20
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now