如果我想在下面的查询中排除某些日期,我该怎么做呢。我想排除日期为25/12/2014的日期。
SELECT *,
(DATEDIFF(dd, [1], next_service)) - (DATEDIFF(wk, [1], next_service) * 2) - (
CASE
WHEN DATENAME(dw, [1]) = 'Sunday'
THEN 1
ELSE 0
END
) - (
CASE
WHEN DATENAME(dw, [1]) = 'Saturday'
THEN 1
ELSE 0
END
) AS days_diff_1,
(DATEDIFF(dd, [2], next_service)) - (DATEDIFF(wk, [2], next_service) * 2) - (
CASE
WHEN DATENAME(dw, [2]) = 'Sunday'
THEN 1
ELSE 0
END
) - (
CASE
WHEN DATENAME(dw, [2]) = 'Saturday'
THEN 1
ELSE 0
END
) AS days_diff_2,
(DATEDIFF(dd, [3], next_service)) - (DATEDIFF(wk, [3], next_service) * 2) - (
CASE
WHEN DATENAME(dw, [3]) = 'Sunday'
THEN 1
ELSE 0
END
) - (
CASE
WHEN DATENAME(dw, [3]) = 'Saturday'
THEN 1
ELSE 0
END
) AS days_diff_3,
(DATEDIFF(dd, u_gas_injunction, next_service)) - (DATEDIFF(wk, u_gas_injunction, next_service) * 2) - (
CASE
WHEN DATENAME(dw, u_gas_injunction) = 'Sunday'
THEN 1
ELSE 0
END
) - (
CASE
WHEN DATENAME(dw, u_gas_injunction) = 'Saturday'
THEN 1
ELSE 0
END
) AS injunction_diff,
DATEADD(day, (- 25 % 5) + CASE ((@@DATEFIRST + DATEPART(weekday, next_service) + (25 % 5)) % 7)
WHEN 0
THEN 2
WHEN 1
THEN 1
ELSE 0
END, DATEADD(week, (- 25 / 5), next_service)) AS apt_target1,
DATEADD(day, (- 18 % 5) + CASE ((@@DATEFIRST + DATEPART(weekday, next_service) + (18 % 5)) % 7)
WHEN 0
THEN 2
WHEN 1
THEN 1
ELSE 0
END, DATEADD(week, (- 18 / 5), next_service)) AS apt_target2,
DATEADD(day, (- 8 % 5) + CASE ((@@DATEFIRST + DATEPART(weekday, next_service) + (8 % 5)) % 7)
WHEN 0
THEN 2
WHEN 1
THEN 1
ELSE 0
END, DATEADD(week, (- 8 / 5), next_service)) AS apt_target3,
DATEADD(day, (- 5 % 5) + CASE ((@@DATEFIRST + DATEPART(weekday, next_service) + (5 % 5)) % 7)
WHEN 0
THEN 2
WHEN 1
THEN 1
ELSE 0
END, DATEADD(week, (- 5 / 5), next_service)) AS injunction_targe
FROM #rk_ap_pivot
答案 0 :(得分:1)
只需在WHERE datefield <> '2014-12-25'
之后添加FROM #rk_ap_pivot
。