在简单的MS Sql Query中我无法获得结果
SELECT * FROM tblActivityTracker
WHERE (WoM IN (NULL, 2))
AND (DateName = DATENAME(weekday, GETDATE()))
请建议
答案 0 :(得分:1)
您不能将null
与IN
子句一起使用。
<强>查询强>
SELECT * FROM tblActivityTracker
WHERE (WoM IN (2) OR Wom is null) -- or Wom = 2 instead of using IN
AND (DateName = DATENAME(weekday, GETDATE()));
答案 1 :(得分:1)
试试这个
SELECT * FROM tblActivityTracker
WHERE (WoM =2 OR Wom IS NULL)
AND (DateName = DATENAME(weekday, GETDATE()));
或试试这个
SELECT * FROM tblActivityTracker
WHERE (WoM in('NULL','2'))
AND (DateName = DATENAME(weekday, GETDATE()));
答案 2 :(得分:1)
你能做的最好就是使用isnull
SELECT * FROM tblActivityTracker
WHERE isnull(WoM,'') IN ('', '2')
AND DateName = DATENAME(weekday, GETDATE())
答案 3 :(得分:0)
感谢您的建议...... 实际上下面的查询有帮助
SELECT * FROM tblActivityTracker
WHERE (WoM IN (2)) AND (DATENAME(weekday, GETDATE()) = DateName) OR
(WoM IS NULL) AND (DATENAME(weekday, GETDATE()) = DateName)