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 2008 Forums
 Transact-SQL (2008)
 Help with SQL query

Author  Topic 

reddy_vam
Starting Member

43 Posts

Posted - 2012-11-06 : 13:22:15
I have a table called Test and it contains 3 fields called id, Current date and description.

I wanted to write a query such that it list out the id, currentdate, description and also (Currentdate-1 year) and description part related to the 1 year back date.

Can someone help me with this query.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-11-06 : 13:43:00
[code]
SELECT t1.*,t2.currentdate as prevyrdate,
t2.description as prevyrdescription
FROM table t1
LEFT JOIN table t2
ON t2.currentdate = DATEADD(yy,-1,t1.currentdate)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -