January 4, 2008 at 7:05 am
Heh... Mom always said, "Never run with scissors"... being in a hurry on code has the same effect on careers.
Anyway, glad you figured it out... and thank for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 7, 2008 at 1:31 am
OP, when you have time, read this
http://sql-server-performance.com/fk_datetime.asp
Failing to plan is Planning to fail
April 18, 2014 at 11:30 pm
declare @DateFrom DateTime = CONVERT(DATETIME, '01/01/2014', 103)
declare @DateTo DateTime = CONVERT(DATETIME, '01/03/2014', 103)
;WITH CTE(dt)
AS
(
Select @DateFrom
Union All
Select DATEADD(d,1,dt)FROM CTE
Where dt<@DateTo
)
select DayName,CONVERT(varchar(50), dt, 103)as Date from (select 'Saturday' as DayName,dt from CTE
where DATENAME(dw,dt)In('Saturday') group by dt
Union
select 'Sunday'as DayName,dt from CTE
where DATENAME(dw,dt)In('Sunday'))as result order by dt
Reference : http://aj-learning.com/blog/get-weekend-date-sql-server-specific-date-range/
April 19, 2014 at 2:46 pm
ajlearningcom (4/18/2014)
declare @DateFrom DateTime = CONVERT(DATETIME, '01/01/2014', 103)declare @DateTo DateTime = CONVERT(DATETIME, '01/03/2014', 103)
;WITH CTE(dt)
AS
(
Select @DateFrom
Union All
Select DATEADD(d,1,dt)FROM CTE
Where dt<@DateTo
)
select DayName,CONVERT(varchar(50), dt, 103)as Date from (select 'Saturday' as DayName,dt from CTE
where DATENAME(dw,dt)In('Saturday') group by dt
Union
select 'Sunday'as DayName,dt from CTE
where DATENAME(dw,dt)In('Sunday'))as result order by dt
Reference : http://aj-learning.com/blog/get-weekend-date-sql-server-specific-date-range/
Please read the following article for why you should generally avoid rCTEs that "count" by 1 like yours does. There are several much more efficient ways to do the same thing.
[font="Arial Black"]Hidden RBAR: Counting with Recursive CTE's[/font][/url]
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply