briangriffin
Programmer
I have a fairly simple query that runs in a few seconds - similar to this:
However, when changing to
then the query takes ten minutes or more.
Why would that be?
So I changed to :
and I get the same results when changing to include or exclude nulls. It seems that once the cte values have been retrieved then getting those values would be immediate regardless of the where clause. This query only returns about ten records including nulls
I would appreciate an explanation as to why this is happening and what I should do about it. TIA
Code:
select
patient,
room,
max(intime) as InTime,
OpDateTime
from some tables
group by patient, room, OpDateTime
where OpDateTime is not null
However, when changing to
Code:
where OpDateTime is null
Why would that be?
So I changed to :
Code:
with cte_test as
(
select
patient,
room,
max(intime) as InTime,
OpDateTime
from some tables
group by patient, room, OpDateTime
)
select * from cte_test where OpDateTime is not null
and I get the same results when changing to include or exclude nulls. It seems that once the cte values have been retrieved then getting those values would be immediate regardless of the where clause. This query only returns about ten records including nulls
I would appreciate an explanation as to why this is happening and what I should do about it. TIA