0

I'm basically trying to produce a report that displays a filtered list of all of our invoices for the current week. (This report will be done on wednesdays, so all of the invoices since the last wednesday)

This is the code that I have for my WHERE statement:

WHERE e.TotalCount = 1 OR e.LastThreeMonths = 1
AND OINV.[TaxDate] >= (GETDATE() - 7)

The first part (e.TotalCount....) is all fine and fits in, but even with the second filter in, the query still returns all of the results regardless of date.

Am I being a complete idiot or should this work as expected to..?

4

1 回答 1

1

添加括号将第二个条件与第三个条件分开:

WHERE (e.TotalCount = 1 OR e.LastThreeMonths = 1)
     AND OINV.[TaxDate] >= (GETDATE() - 7)

AND优先于OR,因此您的标准并未将日期要求应用于所有行,仅适用于具有e.LastThreeMonths = 1

于 2013-08-05T14:26:46.063 回答