DECLARE @Day SmallDateTime
SET @Day = DateAdd(MM, DateDiff(MM,0,'2019-11-21'), 0)
;WITH Temp AS
( SELECT @Day AS RQ UNION ALL
SELECT RQ+1
FROM TEMP WHERE DateDiff(Month,RQ+1,@Day) = 0
)
SELECT
RN = Row_Number() Over(ORDER BY RQ),
RQ
FROM Temp WHERE DatePart(WEEKDAY,RQ)= (07-@@DateFirst) % 7 + 1
DECLARE @RQ SMALLDATETIME
SET @RQ = '2019-09-01';
;WITH
tAppDays (fDay) AS
(
SELECT @RQ AS fDay
UNION ALL
SELECT fDay + 1 FROM tAppDays WHERE DateDiff(Month,fDay+1,@RQ) = 0
)
SELECT * FROM tAppDays ORDER BY fDAY
DECLARE @RQ SMALLDATETIME
SET @RQ = '2019-09-01';
;WITH
tAppDays (fDay) AS
(
SELECT @RQ AS fDay
UNION ALL
SELECT fDay + 1 FROM tAppDays WHERE DateDiff(Month,fDay+1,@RQ) = 0
)
SELECT * FROM tAppDays ORDER BY fDAY
-- 利用递归来获得给定字符串的SPLIT方法
DECLARE @CommentStr NVARCHAR(4000)='总经理室|销售部|会计部|人事部|工会|后勤部|生产计划部|动力分厂|质量检验部|运输部'
DECLARE @Split NVARCHAR(1)='|';
WITH Temp AS
( SELECT 1 AS Num UNION ALL
SELECT Num + 1
FROM TEMP WHERE Num<Len(@CommentStr) )
SELECT
RN = Row_Number() Over(ORDER BY Num),
SplitStr = SUBSTRING(@CommentStr,Num,CHARINDEX(@Split,@CommentStr+@Split,Num)-Num)
FROM Temp WHERE SUBSTRING(@Split+@CommentStr,Num,1) = @Split OPTION(MAXRECURSION 0);
--================================================================================================
-- pAppGetSplit '|','科目名称|身份证号|学员姓名|教练编号|教练姓名|培训次数|合计次数|负责比例'
================================================================================================
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'pAppGetSplit' AND type = 'P')
DROP PROCEDURE pAppGetSplit
GO
CREATE PROCEDURE pAppGetSplit
@Split VARCHAR(1),
@STR NVARCHAR(4000)
AS
;WITH Temp AS -- 根据分隔符|获得字段列表
( SELECT 1 AS Num UNION ALL
SELECT Num + 1
FROM TEMP WHERE Num<Len(@STR) )
SELECT
RN = Row_Number() Over(ORDER BY Num),
SplitStr = SUBSTRING(@STR,Num,CHARINDEX(@Split,@STR+@Split,Num)-Num)
FROM Temp WHERE SUBSTRING(@Split+@STR,Num,1) = @Split OPTION(MAXRECURSION 0);
GO