私は本当にいくつかの助けを使うことができます。CTE 内の VARCHAR レポート パラメータから 1 を減算しようとしています。私はSQL 2008 R2で作業しています
これはうまくいきます:
AND MONTH(CAST(c.DATETIME AS DATE)) = CONVERT(INT,@Maand)
しかし、これはうまくいかないようです:
AND MONTH(CAST(c.DATETIME AS DATE)) = CONVERT(INT,@Maand) -1
ありがとう
これが私のコードの一部です:
ALTER PROCEDURE [rpt].[usp_F_Telefonie_Bereikbaarheid](@Jaar AS VARCHAR(4), @Maand AS VARCHAR(2))
AS
BEGIN
WITH CTE AS(
SELECT
C.DATETIME AS Datum
,d.NAME
,COUNT(Callid) AS Aantal
,'Vorige' AS Gesprekken
,DURATIONSEC
FROM DM.dm.F_CDRS AS c
JOIN DM.dm.D_DEPARTMENTS AS d
ON d.DEPARTMENTID = c.DEPARTMENTID
WHERE Direction = 1
AND YEAR(CAST(c.DATETIME AS DATE)) = @Jaar
AND MONTH(CAST(c.DATETIME AS DATE))= CONVERT(INT,@Maand)
AND WAITTIMESEC <=10
GROUP BY LEFT(D.NAME, 2), D.NAME, C.DATETIME, DURATIONSEC
)
SELECT
,CASE CTE.Gesprekken
WHEN 'Vorige'
THEN SUM(CTE.Aantal)
END AS Vorige
FROM CTE
WHERE MONTH(CAST(CTE.Datum AS DATE)) = @Maand
AND YEAR(CAST(CTE.Datum AS DATE)) = @Jaar
GROUP BY CTE.NAME, CTE.Gesprekken, CTE.DURATIONSEC, CTE.Aantal