SQL不是我的强项,但是我无法弄清楚为什么它不起作用。我只是想基于一个值运行一个不同的AND语句。具体来说,如果foo =0,我想在dateDiff函数中更改datePart
SELECT foo, bar, test FROM table WHERE bar = 1, CASE WHEN foo = 0 AND dateDiff(dd, getDate(), 2 ) < test ELSE AND dateDiff(hh, getDate(), 2 ) < test END
试试这个-
SELECT foo, bar, test FROM [table] WHERE bar = 1 AND ( ( foo = 0 AND DATEDIFF(dd, GETDATE(), 2 ) < test ) OR DATEDIFF(hh, GETDATE(), 2 ) < test )