Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

Help with query against AdventureWorks database - Update sales price

Need a hand with this query:

Update the Sale Price to the Recommended Sale Price of those Sales occurring between 6/10/2004 and 6/20/2004.

I've got this so far:

SELECT DISTINCT p.ProductID, p.Name, p.ListPrice, sd.UnitPrice As 'Selling Price'
FROM Sales.SalesOrderDetail AS sd
JOIN Production.Product AS p
ON sd.ProductID = p.ProductID AND sd.UnitPrice < p.ListPrice
WHERE ...

Thanks!
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

You would use an update with a JOIN:


{deleted by Mod_MarlEE, 2010-08-29 18:20}

Open in new window

Avatar of John500

ASKER

Ok, great - I'll look at this
Good.  Once you understand this, it should help you with some of the other queries you are trying to figure out ...

This one is in the AdventureWorks structure, so should run "as-is".  The important thing to gather here is that datetime conversion of '2004-06-10' is '2004-06-10 00:00:00' which is midnight on June 10.  The best way to be assured you get all the timestamps of a given day is to look at rows that are < midnight of the next day; therefore, you wanted '2004-06-20', but what I have written is < '2004-06-21' for that reason.

Hope that makes sense.
John,

Just out of curiosity, are these homework questions?  Given how long have been on this site (unless you are sharing the login), are you embarking on re-education?
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John500

ASKER

In regard to the 'recommended sale price' aspect of this question, it appears a referrence is being made to the Database Engine Tuning Advisor.  The following link points to a discussion which illustrates how recommendations are made:

http://sqlblog.com/blogs/ben_nevarez/archive/2009/11/11/database-engine-tuning-advisor-and-the-query-optimizer.aspx

As stated in the discussion, "When the DTA analysis finishes, run this query to inspect the contents of the msdb..DTA_reports_query table:  select * from msdb..DTA_reports_query"

StatementString                                    |      CurrentCost       |       Recommended Cost
-----------------------------------------------------------------------------------------------------
select * from dbo.SalesOrderDetail             1.2434                       0.00328799
where productid = 897

Although this discussion reveals where the recommended price comes from, I'm not sure how to incorporate the recommendation into and UPDATE statement.

Any input on this?  Thanks !




Avatar of John500

ASKER

Scratch that last post.  I realize now this recommendation deals with indexes and query execution time...