日期:2014-05-17 浏览次数:20507 次
select DATEADD(day,number,convert(varchar(7),GETDATE(),120)+'-01') as a,
case when DATEPART(WEEKDAY,DATEADD(day,number,convert(varchar(7),GETDATE(),120)+'-01')) not in (1,7) then '上班'
else '放假' end as 安排
from master.dbo.spt_values
where type='p'
declare @month datetime = '2014-1-1'
declare @days int
set @month = DATEADD(day, 1-datepart(day, @month), @month)
set @days = DATEDIFF(day, @month, dateadd(MONTH, 1, @month))
;
with day as (
select DATEADD(day,number,@month) date,DATEPART(weekday, DATEADD(day,number,@month)) week from master..spt_values where type='P' and number<@days
)
select date, case when week=1 or week=7 then '休息' else '上班' end from day
DECLARE @ym CHAR(6)
SET @ym='201401'
;WITH a1 AS
(
SELECT CAST(@ym+'01' AS DATETIME) date_d
UNION ALL
SELECT DATEADD(d,1,date_d) FROM a1
WHERE CONVERT(CHAR(6),DATEADD(d,1,date_d),112)=@ym
)
,a2 AS
(
SELECT *,DATEPART(weekday,date_d) week_day
FROM a1
)
SELECT *,CASE WHEN week_day IN (1,7) then '休息' else '上班' end
FROM a2
with t as
(select dateadd(d,number,stuff(convert(varchar,getdate(),23),9,2,'01')) 'd'
from master.dbo.spt_values
where type='P' and
datediff(m,
stuff(convert(varchar,getdate(),23),9,2,'01'),
dateadd(d,number,stuff(convert(varchar,getdate(),23),9,2,'01')))=0)
select convert(varchar(20),d,23) 'd',
case datepart(dw,d) when 1 then '星期日'
when 2 then '星期一'
&