We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
declare @yr int, @mo tinyint set @yr = 2014 set @mo = 6 ; with dates( dt ) as ( -- select 1st day of month constructed from year and month inputs select convert( datetime, convert( char(8), @yr * 10000 + @mo * 100 + 1 ) ) union all -- facilitates recursion -- add in remainder of days in month select dt + 1 from dates -- keeps adding until the next day would be 1st of next month where day( dt + 1 ) <> 1 ) , dates_tagged( dt, dw, occurrence, occurrence_reverse ) as ( select dt, datepart( weekday, dt ) , row_number() over( partition by datepart( weekday, dt ) order by dt ) , row_number() over( partition by datepart( weekday, dt ) order by dt desc ) from dates ) select dt, dw, occurrence, occurrence_reverse from dates_tagged where dw = 3 and occurrence = 2 --I added this ;
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|Does INTERSECT return opposite from FULL OUTER JOIN?||4||41|
|T-SQL: need to reset a declared variable||4||33|
|SQL Server set parent recort in select with row number||8||28|
Join the community of 500,000 technology professionals and ask your questions.