Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 getting values for this day last year

Author  Topic 

djschlie
Starting Member

3 Posts

Posted - 2004-11-23 : 22:40:11
Hi

I have a table called sales, which stores a date and an actual sales amount, as well as other info.

I need to get the actual sales amount for that day last year that returns from a query the following example:

CurrentDate lastyeardate currentSales LastYearSales
17/11/2004 19/11/2003 1234 2345

I can get the lastyeardate, but am having trouble getting the lastyearsales.

any help would be appreciated
thanks

B0g
Starting Member

19 Posts

Posted - 2004-11-24 : 03:53:31
I think your query should look like this:

SELECT CurentDate,
DATEADD(YY, -1, Curentdate) AS LastYearDate,
CurentSales,
(SELECT CurentSales FROM Sales WHERE CurrentDate = DATEADD(YY, -1, Curentdate)) AS LastYearSales
FROM Sales
WHERE CurentDate = @CurentDate
Go to Top of Page
   

- Advertisement -