Solved

Advanced Update query

Posted on 2003-10-23
2
638 Views
Last Modified: 2012-06-27
I have 2 tables:

Table 1
OrderID
ProductID
ItemQuantity
ItemName
ItemCost


Table 2
SessionID
ProductID
ItemQuantity

What I am trying to do is update Table1.ItemQuantity with values of Table2.ItemQuantity where their productIDs are equal.


Thanks for your help
0
Comment
Question by:zagnutts
2 Comments
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 125 total points
ID: 9611545
Update Table1
Set ItemQuantity = Table2.ItemQuantity
From Table1
         Inner Join Table2 On Table1.ProductID = Table2.ProductID

Also, please maintain this old open question:
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20725832.html

Thanks,
Anthony
0
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 125 total points
ID: 9611570
What  is the PK for Table1, Table2?

In the scenario illustrated below, should the ItemQuantity be updated with value 5 or 6?

Table1
Product1D ItemQuantity
===============
1             4        
2             ?

Table2
Product1D ItemQuantity
===============
1             4        
2             5
2             6

SQL you are asking for is listed below. But the update may be incorrect?

Update Table1
Set      ItemQuatity = Table2.ItemQuantity
FROM Table2
WHERE Table1.ProductId = Table2.ProductId

HTH

Namasi Navaretnam




0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 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

17 Experts available now in Live!

Get 1:1 Help Now