MSSQL返回季度开始月和某月是第几季度
生活随笔
收集整理的這篇文章主要介紹了
MSSQL返回季度开始月和某月是第几季度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/**//*
CREATE?FUNCTION?dbo.sys_GetQuarterBeginDate(@month?smalldatetime)
RETURNS?smalldatetime
AS
--function?:?返回季度的開始月
BEGIN
DECLARE?@dt?smalldatetime
IF?MONTH(@month)?<?4
??????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month)?)+?'-1-1'
ELSE
BEGIN
??????IF?MONTH(@month)?<?7
?????????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month))+?'-4-1'
??????ELSE
????????BEGIN
IF?MONTH(@month)?<?10
?????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month))?+?'-7-1'
ELSE
?????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month)?)+?'-10-1'
????????END
END
????RETURN?@dt
END
*/
調用:select?dbo.sys_GetQuarterBeginDate('2007-6-28')
===========================================================================================================
/**//*
CREATE?FUNCTION?dbo.sys_GetQuarter(@month?smalldatetime)
RETURNS?int
AS
--function?:?返回某月是第幾季度
BEGIN
DECLARE?@qw?int
SELECT?@qw?=?CASE?MONTH?(@month)
?????WHEN?1????THEN?1
?????WHEN?2????THEN?2
?????WHEN?3????THEN?3
?????WHEN?4????THEN?1
?????WHEN?5????THEN?2
?????WHEN?6????THEN?3
?????WHEN?7????THEN?1
?????WHEN?8????THEN?2
?????WHEN?9????THEN?3
?????WHEN?10?THEN?1
?????WHEN?11?THEN?2
?????WHEN?12?THEN?3
END?
????RETURN?@qw
END
*/
CREATE?FUNCTION?dbo.sys_GetQuarterBeginDate(@month?smalldatetime)
RETURNS?smalldatetime
AS
--function?:?返回季度的開始月
BEGIN
DECLARE?@dt?smalldatetime
IF?MONTH(@month)?<?4
??????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month)?)+?'-1-1'
ELSE
BEGIN
??????IF?MONTH(@month)?<?7
?????????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month))+?'-4-1'
??????ELSE
????????BEGIN
IF?MONTH(@month)?<?10
?????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month))?+?'-7-1'
ELSE
?????SET?@dt?=?CONVERT(VARCHAR,YEAR(@month)?)+?'-10-1'
????????END
END
????RETURN?@dt
END
*/
調用:select?dbo.sys_GetQuarterBeginDate('2007-6-28')
===========================================================================================================
/**//*
CREATE?FUNCTION?dbo.sys_GetQuarter(@month?smalldatetime)
RETURNS?int
AS
--function?:?返回某月是第幾季度
BEGIN
DECLARE?@qw?int
SELECT?@qw?=?CASE?MONTH?(@month)
?????WHEN?1????THEN?1
?????WHEN?2????THEN?2
?????WHEN?3????THEN?3
?????WHEN?4????THEN?1
?????WHEN?5????THEN?2
?????WHEN?6????THEN?3
?????WHEN?7????THEN?1
?????WHEN?8????THEN?2
?????WHEN?9????THEN?3
?????WHEN?10?THEN?1
?????WHEN?11?THEN?2
?????WHEN?12?THEN?3
END?
????RETURN?@qw
END
*/
轉載于:https://www.cnblogs.com/jinweida/archive/2008/07/07/1237428.html
總結
以上是生活随笔為你收集整理的MSSQL返回季度开始月和某月是第几季度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几种适合开发用的在线编辑器-推荐及下载
- 下一篇: web服务压力测试)有效的压力测试系统将