gpt4 book ai didi

使用临时列的 SQL Server WHERE 子句

转载 作者:行者123 更新时间:2023-12-03 23:56:28 24 4
gpt4 key购买 nike

我有以下查询,它使用 CASE 语句。无论如何要添加到 where 子句 WHERE IsBusinessDayFinal = 0?不使用临时表?

非常感谢!

SELECT 
ac.DateTimeValue,
CASE
WHEN pc.IsBusinessDay IS NOT NULL THEN pc.IsBusinessDay
ELSE ac.IsBusinessDay
END AS IsBusinessDayFinal,
ac.FullYear,
ac.MonthValue,
ac.DayOfMonth,
ac.DayOfWeek,
ac.Week
FROM
[dbo].[AdminCalendar] ac LEFT JOIN
[dbo].ProjectCalendar pc ON ac.DateTimeValue = pc.DateTimeValue AND pc.ProjectId = @projectId
WHERE ac.DateTimeValue >= @startDate AND ac.DateTimeValue <= @finishDate;

最佳答案

使用

WHERE (pc.IsBusinessDay IS NULL AND ac.IsBusinessDay = 0)
OR pc.IsBusinessDay = 0

关于使用临时列的 SQL Server WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1892071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com