I had a requirement to get second and forth Saturday in a month.
Here is a SQL Server query which allow to get it done.
select *
from (
select datein2n4,
datename( weekday, datein2n4 ) as wkdy,
row_number( ) over ( partition by datepart( month, datein2n4 ), datename( weekday, datein2n4 ) order by datein2n4 ) as rn_dy_mth
from (
select dateadd( day, rn, cast( '2017-05-29 00:00:00' as date ) ) as datein2n4
from (
select row_number() over( order by object_id ) - 1 as rn
from sys.columns
) as rn
) as dy
) as dy_mth
where rn_dy_mth in ( 2, 4 )
and wkdy = 'Saturday'
order by datein2n4
Here is a SQL Server query which allow to get it done.
select *
from (
select datein2n4,
datename( weekday, datein2n4 ) as wkdy,
row_number( ) over ( partition by datepart( month, datein2n4 ), datename( weekday, datein2n4 ) order by datein2n4 ) as rn_dy_mth
from (
select dateadd( day, rn, cast( '2017-05-29 00:00:00' as date ) ) as datein2n4
from (
select row_number() over( order by object_id ) - 1 as rn
from sys.columns
) as rn
) as dy
) as dy_mth
where rn_dy_mth in ( 2, 4 )
and wkdy = 'Saturday'
order by datein2n4
0 comments :
Post a Comment