I need help with rewriting a query.
I'm using SQL Server with crystal reports 8.
I ran my query thru sql query analyzer and checked the Estimated Execution Plan; I also got advice from some contributors to tek-tips.
My query is not optimized because of the number of Table Scans it is performing.
Particularly, it's taking a long time to process this WHERE clause:
WHERE ((BillAssignments.BillNum IS NOT NULL AND
Requests.BillNum IS NOT NULL) OR
(Bill.Sponsor <> 'Budget' AND (Bill.Bill99Code = 'Y' OR
(Bill.InWAM = 'Y' AND (Bill.BAMCode IN ('R', 'X', 'U')))) AND
CommitteeActions.ActionCode IS NULL))
ORDER BY Bill.BillNum, BillAssignments.Analyst
Is there some way I can rewrite this and maximize performance?
I thought I could take out the first two NOT NULL statements because I looked in the database and both of these fields had Allow Nulls unchecked. I thought this meant that this field could never be NULL.
But when I went back to run the query, I got back about half as many records: about 600.
Can someone explain this or suggest alternatives to checking for IS NOT NULL or IS NULL?
Thanks in advance.
I'm using SQL Server with crystal reports 8.
I ran my query thru sql query analyzer and checked the Estimated Execution Plan; I also got advice from some contributors to tek-tips.
My query is not optimized because of the number of Table Scans it is performing.
Particularly, it's taking a long time to process this WHERE clause:
WHERE ((BillAssignments.BillNum IS NOT NULL AND
Requests.BillNum IS NOT NULL) OR
(Bill.Sponsor <> 'Budget' AND (Bill.Bill99Code = 'Y' OR
(Bill.InWAM = 'Y' AND (Bill.BAMCode IN ('R', 'X', 'U')))) AND
CommitteeActions.ActionCode IS NULL))
ORDER BY Bill.BillNum, BillAssignments.Analyst
Is there some way I can rewrite this and maximize performance?
I thought I could take out the first two NOT NULL statements because I looked in the database and both of these fields had Allow Nulls unchecked. I thought this meant that this field could never be NULL.
But when I went back to run the query, I got back about half as many records: about 600.
Can someone explain this or suggest alternatives to checking for IS NOT NULL or IS NULL?
Thanks in advance.