Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Declare @begin datetimedeclare @end datetime leave ---table leaveid -pk begindate datetime enddate datetime---------------------------leave id begindate enddate--------------------------- 1 1/25/2009 2/5/2009 how about if i get the range on the middle of the begindate and enddate??i want a count that will specify the date between the begindate and enddate...............i want an output goes like this!...1/29/20091/30/20091/31/20092/1/20092/2/20092/3/20094/4/2009pls. help me...thank you in advance!
Jai Krishna
Constraint Violating Yak Guru
333 Posts
Posted - 2009-02-08 : 23:13:21
What About 1/26/2009,1/27/20091/28/2009these dates dont u need them in ur o/pJai Krishna
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2009-02-09 : 03:03:47
[code]DECLARE @Sample TABLE ( LeaveID INT IDENTITY(1, 1) PRIMARY KEY, BeginDate DATETIME, EndDate DATETIME )INSERT @SampleSELECT '1/25/2009', '2/5/2009'SELECT s.*, DATEADD(DAY, v.Number, s.BeginDate) AS PesoFROM @Sample AS sINNER JOIN master..spt_values AS v ON v.Type = 'P' AND v.Number <= DATEDIFF(DAY, BeginDate, EndDate)[/code]E 12°55'05.63"N 56°04'39.26"
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-02-09 : 03:21:48
Also
;With Date_CTE ([leave id],DateVal,enddate)AS(SELECT [leave id],begindate,enddateFROM tableUNION ALLSELECT [leave id],DATEADD(dd,1,begindate),enddateFROM Date_CTE WHERE DATEADD(dd,1,begindate) <=enddate)SELECT [leave id],DateVal FROM Date_CTE OPTION(MAXRECURSION 0)