SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

reddy_vam
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.

Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52249 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
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000