.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

SQL query to update date range

Posted By: Santosh     Posted Date: May 11, 2015    Points:5   Category :Sql Server
i am trying to find the output for the below but couldnt do ..some one please provide the solution

i am passing startdate and enddate , and for the startdate if any record is there then that record will move to next date of this range.keep on updating startdate and enddate until its not falling in any range.

in sample i would say duplicate record should not be there in any range.

Type Start Date End Date
1 Test1 03-05-2015 07-05-2015
2 Test1 12-05-2015 15-05-2015
3 Test1 17-05-2015 22-05-2015
4 Test1 23-05-2015 28-05-2015
5 Test1 05-06-2015 09-06-2015
6 Test2 05-05-2015 10-05-2015

while Test2 is updating as test1 then output should be like below.
here startdate(05-05-2015) is falling between(03-05-2015-07-05-2015) of Sr 1 so this start date is changed to next of end date(07-05-201 +1 and 07-05-2015+1+(10-05-2015-05-05-2015)) .
1 Test1 03-05-2015 07-05-2015
6 Test1 08-05-2015 13-05-2015 Test2 will update as Test1 and startdate and end date
2 Test1 14-05-2015 17-05-2015
3 Test1 18-05-2015 23-05-2015
4 Test1 24-05-2015 29-05-2015
5 Test1 05-06-2015 10-06-2015 no change 29-05-2015 is not between this range

if two record ranges are falling then 2 should move accordingly.
i'e if INPUT is (05-05-2015 to 26-05-2015)
this 2 records are falling in range
1 Test1 03-05-2015 07-05-2015
2 Test1 12-05-2015 15-05-2015



No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend