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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with SQL query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

43 Posts

Posted - 11/06/2012 :  13:22:15  Show Profile  Reply with Quote
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.


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/06/2012 :  13:43:00  Show Profile  Reply with Quote

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)

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000