| Author |
Topic  |
|
asp__developer
Yak Posting Veteran
74 Posts |
Posted - 10/04/2012 : 10:30:09
|
I am trying this
SELECT TOP 5 StartD, EndD FROM MYTable AS t WHERE StartD AND EndD > (DATEADD(d,DATEDIFF(d,0,GETDATE())+2,0) BETWEEN StartD AND EndD)
Please help ?
Instead of adding 14 days 5 times to start and end date - I think another logic is displaying next 5 rows in asce or desc order because when our logic will give start and end date, the next 5 rows of that result are the next pay periods because I have saved everything in the database in proper order not randomly |
Edited by - asp__developer on 10/04/2012 10:34:03 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47069 Posts |
Posted - 10/04/2012 : 10:42:30
|
did you see the link i posted see logic used inside and try it out yourself. and if you face further issues we will help. Dont always rely upon spoonfed answers!
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
asp__developer
Yak Posting Veteran
74 Posts |
Posted - 10/04/2012 : 19:52:39
|
quote: Originally posted by visakh16
did you see the link i posted see logic used inside and try it out yourself. and if you face further issues we will help. Dont always rely upon spoonfed answers!
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
I am not relying on spoonfed answers as you can see I am trying and infact it was my logic based on which I was asking help here.
Above I posted what I was thinking and a new logic and based on my new logic and your tutorial I have figured out the problem by this statement
with CTE as ( SELECT TOP 1 StartDate, EndDate FROM Table_Date AS t WHERE (DATEADD(d, DATEDIFF(d, 0, GETDATE()) + 2, 0) BETWEEN StartDate AND EndDate) ORDER BY StartDate )
SELECT StartDate, EndDate FROM (select top 5 t.StartDate, t.EndDate from Table_Date AS t cross join CTE as c where t.StartDate > c.StartDate order by t.StartDate) as n |
 |
|
Topic  |
|
|
|