Solved

SQL Update 1 tables columns from a different tables columns

Posted on 2007-11-28
4
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Results to Excel File 18 76
performance query 4 37
MS SQL GROUP BY 6 75
Convert string date and select older than 30 days from today 2 41
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. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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