On a different note, please consider taking full advantage of the explicit JOIN
syntax to separate different kinds of conditions. The c.Id = d.Id
part is a joining condition while the others are filtering conditions. A joining condition would make most sense in the ON
clause. So instead of CROSS JOIN ... WHERE <joining_condition>
, use INNER JOIN ... ON <joining_condition>
, like this:
select *
from dbo.C c
inner join dbo.D d on c.Id = d.Id -- joining condition, moved from WHERE
where -- filtering conditions go here
(c.BookId = 11 or c.BookId = 12) -- BookId is 11 or 12
and ... /* the rest of the conditions */