Re: IS NULL not working in WHERE clause.
From: Steve Kass (skass_at_drew.edu)
Date: 12/17/04
- Next message: Bob Barrows [MVP]: "Re: Returning single value"
- Previous message: asturt_at_us.ci.org: "Re: Avoiding Invalid Column Name"
- In reply to: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Next in thread: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Reply: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Reply: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 17 Dec 2004 18:33:34 -0500
Earl,
Is there no clustered index or primary key on the big table?
While that shouldn't matter, maybe it's a clue - it's not a great
idea, either, but I doubt you want to add one just now. I suspect
something is corrupt, and if you could find out the following,
it might help:
Look at the estimated execution plan for
A. The bad query on the big table.
B. The good query on the big table.
In particular, let me know which index is being used at
the start of the query (or indexes, if the query uses
separate indexes for separate parts of the where condition).
You can also try adding an index hint to see if that helps. If
the query plans are different, add a hint to mention the name
of the index used when the query works, probably
from pmix_fact1 with (index (IX_pmix_fact1_6))
Also, if there is a parallel query plan, try adding the hint
OPTION (MAXDOP 1)
after the order by clause.
Of course if you haven't run DBCC CHECKTABLE and can afford to, that's
probably something to do before fiddling.
Steve Kass
Drew University
Earl Newcomer wrote:
>The query with the between clause is the one that works. It is the other
>query that is not running consistently against different tables. The first
>query against a table with 277 million rows returns rows where the time_id is
>NOT NULL. The same query run against a table with 655,000 rows only returns
>rows where the time_id is NULL.
>
>"Aaron [SQL Server MVP]" wrote:
>
>
>
>>Put your BETWEEN clauses in parentheses, e.g.
>>
>>WHERE someting = smething
>>AND (some_COL BETWEEN something AND something)
>>AND something_else IS NULL
>>
>>Or, don't use BETWEEN at all.
>>http://www.aspfaq.com/2280
>>
>>--
>>http://www.aspfaq.com/
>>(Reverse address to reply.)
>>
>>
>>
>>
>>"Earl" <Earl@discussions.microsoft.com> wrote in message
>>news:2C486DD9-BD80-46A6-979A-082457CD2029@microsoft.com...
>>
>>
>>>The following query returns rows where the time_id IS NOT NULL. This
>>>
>>>
>>query
>>
>>
>>>seems to be breaking SQL Server(?)
>>>
>>>select bus_date, time_ordered, time_id
>>> from [vicorp\gillic].pmix_fact1
>>> where bus_date = '2003-11-01'
>>> and time_id is null
>>>order by time_ordered
>>>
>>>
>>>The following query does NOT return any rows where the time_id is null.
>>>
>>>select bus_date, time_ordered, time_id
>>> from [vicorp\gillic].pmix_fact1
>>> where bus_date = '2003-11-01'
>>> and time_ordered between '2003-10-31 00:05:54' and '2003-11-05
>>>
>>>
>>13:38:11'
>>
>>
>>> and time_id is null
>>>order by time_ordered
>>>
>>>
>>>
>>>
>>
>>
>>
- Next message: Bob Barrows [MVP]: "Re: Returning single value"
- Previous message: asturt_at_us.ci.org: "Re: Avoiding Invalid Column Name"
- In reply to: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Next in thread: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Reply: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Reply: Earl Newcomer: "Re: IS NULL not working in WHERE clause."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|