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.
| Author |
Topic |
|
djschlie
Starting Member
3 Posts |
Posted - 2004-11-23 : 22:40:11
|
| HiI 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 LastYearSales17/11/2004 19/11/2003 1234 2345I can get the lastyeardate, but am having trouble getting the lastyearsales.any help would be appreciatedthanks |
|
|
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 LastYearSalesFROM SalesWHERE CurentDate = @CurentDate |
 |
|
|
|
|
|