Hi, I asked the opposite question here, now I am faced with another problem. Assume I have the following tables (as per poster in previous post)
CustID LastName FirstName ------ -------- --------- 1 Woman Test 2 Man Test ProdID ProdName ------ -------- 123 NY Times 234 Boston Globe ProdID IssueID PublishDate ------ ------- ----------- 123 1 12/05/2008 123 2 12/06/2008 CustID OrderID OrderDate ------ ------- --------- 1 1 12/04/2008 OrderID ProdID IssueID Quantity ------- ------ ------- -------- 1 123 1 5 2 123 2 12
How do I obtain the previous issue (publishdate) from table 3, of all issue, by WeekDay name? The presious issue of today (Wednesday) will not be yesterday Tuesday but last week Wednesday. The result will be 3 columns. The Product Name, current issue (PublishDate) and previous issue (PublishDate).
Thanks
Edit ~ Here is a problem I am facing. What if the previous issue doesn't exists, it has to go back to the pror week as well. I tried the following as a test but doesn't work
SELECT TOP 1 publishdate FROM dbo.issue
WHERE prodid = 123 AND datename(dw,publishdate) = datename(dw,'2008-12-31')
ORDER BY publishdate desc
This is on SQL Server 2000.