データ型について質問があります。次のコード行は、データベースで機能します。
WHERE e_ru IN (5420,5410,5550,6230,6240,6250)
e_ru
ここで、月ごとに異なる数字のセットを挿入したいと思います。
DECLARE @StartDate DATETIME, @EndDate DATETIME, @MonthOfYear TINYINT, @RUsToAudit NVARCHAR
SET @StartDate = (dateadd(month, datediff(month, 0, DATEADD(month, -6, GETDATE())),0)+15)
SET @EndDate = (dateadd(month, datediff(month, 0, DATEADD(month, 0, GETDATE())),0)+14)
SET @MonthOfYear = DATEPART(month, GETDATE())
SET @RUsToAudit =
CASE
WHEN @MonthOfYear = 1 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 2 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 3 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 4 THEN (SELECT 5460,5470,5500)
WHEN @MonthOfYear = 5 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 6 THEN (SELECT 5530,5910)
WHEN @MonthOfYear = 7 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 8 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 9 THEN (SELECT 5460,5470,5500)
WHEN @MonthOfYear = 10 THEN (SELECT 5420,5410,5550,6230,6240,6250)
WHEN @MonthOfYear = 11 THEN (SELECT 5530,5910)
WHEN @MonthOfYear = 12 THEN (SELECT 5420,5410,5550,6230,6240,6250)
END
SELECT @StartDate AS 'Report Start Date', @EndDate AS 'Report End Date', @MonthOfYear AS 'Month', @RUsToAudit AS 'Programs'