查询给定日期是当月的第几周sql查询语句
declare @date datetime;
set @date = getdate()
--思路,给定日期是当年的第几周-给定日期所在月第一天是当年的第几周
select datepart(week,@date)-datepart(week,dateadd(month,datediff(month,0,@date),0))+1 [weekofmonth]
select datepart(week,@date)-datepart(week,dateadd(day,1-datepart(day,@date),@date))+1 [weekofmonth]
go