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
 General SQL Server Forums
 New to SQL Server Programming
 Query 2 dates values results on same row
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

infodemers
Posting Yak Master

Canada
181 Posts

Posted - 09/26/2012 :  18:35:48  Show Profile  Reply with Quote
Hi,
I have to run a query to get the Treshold values for a range of date.
Like--> Select Treshold from table1
where([Date] >= '2012-01-01' and [Date] <= '2012-09-01')
or ([Date] >= '2011-01-01' and [Date] <= '2011-09-01')

For every results, I would need to have it like this

------------------------------------------------
Treshold(for 2011-01-01)|Treshold(for 2012-01-01)
-------------------------------------------------
Treshold(for 2011-02-01)|Treshold(for 2012-02-01)
-------------------------------------------------
Treshold(for 2011-03-01)|Treshold(for 2012-03-01)
-------------------------------------------------

Thanks !

infodemers
Posting Yak Master

Canada
181 Posts

Posted - 09/26/2012 :  21:11:35  Show Profile  Reply with Quote
Never mind everyone,

I found out a way of getting it done.

Select t2.Treshold as PreviousTreshold, t1.Treshold from table1 t1
left outer join (Select Treshold from table1
Where (t2.[Date] >= '2011-01-01' and t2.[Date] <= '2011-09-01')) as t2 on Month(t2.date) = Month(t1.date)
where (t1.[Date] >= '2012-01-01' and t1.[Date] <= '2012-09-01')
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.08 seconds. Powered By: Snitz Forums 2000