if exists(SELECT *FROM [DBPersonnel].[dbo].[TB証明書] where [社員番号]='001') update [DBPersonnel].[dbo].[TB証明書] set [身分証明書]='11' where [社員番号]='001' else INSERT INTO [DBPersonnel].[dbo].[TB証明書] ([社員番号],[身分証明書],[卒業証書]) VALUES ('001','sssss','ssssss') 取得本月天数 select datediff(day,cast(month(GetDate()) as varchar)+'-'+cast(month(GetDate()) as varchar)+'-15' ,cast(month(GetDate()) as varchar)+'-'+cast(month(GetDate())+1 as varchar)+'-15') 一个季度多少天 declare @m tinyint,@time smalldatetime select @m=month(getdate()) select @m=case when @m between 1 and 3 then 1 when @m between 4 and 6 then 4 when @m between 7 and 9 then 7 else 10 end select @time=datename(year,getdate())+'-'+convert(varchar(10),@m)+'-01' select datediff(day,@time,dateadd(mm,3,@time)) 判断是否闰年: SELECT case day(dateadd(mm, 2, dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)))) when 28 then '平年' else '闰年' end 或者 select case datediff(day,datename(year,getdate())+'-02-01',dateadd(mm,1,datename(year,getdate())+'-02-01')) when 28 then '平年' else '闰年' end
所有休息日
DECLARE @Work_LegalHoliday TABLE
(
ID VARCHAR(36) ,
DateTimeName DATETIME ,
WeekName VARCHAR(50) ,
IsLegalHoliday INT ,
Remark NVARCHAR(MAX)
)
DECLARE @Year INT
SET @Year = 2015
--
;
WITH tbSource
AS ( SELECT CAST(RTRIM(@Year) + '-01-01' AS DATETIME) DateTimeName
UNION ALL
SELECT DATEADD(dd, 1, DateTimeName)
FROM tbSource
WHERE DATEPART(yy, DATEADD(dd, 1, DateTimeName)) = @Year
)
INSERT @Work_LegalHoliday
SELECT NEWID() ,
CONVERT(VARCHAR(10), DateTimeName, 121) ,
DATENAME(WEEKDAY, DateTimeName) ,
0 ,--不是法定假日
'' AS Remark
FROM tbSource a
WHERE DATEPART(WEEKDAY, a.DateTimeName) = 1
OR DATEPART(WEEKDAY, a.DateTimeName) = 7
EXCEPT
SELECT NEWID() ,
CONVERT(VARCHAR(10), DateTimeName, 121) ,
DATENAME(WEEKDAY, DateTimeName) ,
0 ,
'' AS Remark
FROM @Work_LegalHoliday
OPTION ( MAXRECURSION 0 )
SELECT *
FROM @Work_LegalHoliday