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
 General SQL Server Forums
 New to SQL Server Programming
 Query 2 dates values results on same row

Author  Topic 

infodemers
Posting Yak Master

183 Posts

Posted - 2012-09-26 : 18:35:48
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

183 Posts

Posted - 2012-09-26 : 21:11:35
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
   

- Advertisement -