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)
 How to display START date and END date
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

asp__developer
Posting Yak Master

108 Posts

Posted - 10/04/2012 :  10:30:09  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/04/2012 :  10:42:30  Show Profile  Reply with Quote
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/

Go to Top of Page

asp__developer
Posting Yak Master

108 Posts

Posted - 10/04/2012 :  19:52:39  Show Profile  Reply with Quote
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
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 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