Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Slow Query

Author  Topic 

tc
Starting Member

11 Posts

Posted - 2006-02-14 : 09:44:02
When I run the following query it runs in under a second:

SELECT
convert(varchar, HistDate, 101) as Date
FROM dbo.viewCrewDataL1
WHERE
HistDate >= '01/01/2006'
order by histdate

But when I add " and Crew = 'H' " to the where clause it takes 10 seconds, any ideas on how to speed this up?

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-02-14 : 10:44:39
Add crew as a second column of the index on histDate if both columns are from the same table and performance of this query is critical
Go to Top of Page

tc
Starting Member

11 Posts

Posted - 2006-02-14 : 10:50:19
I apologize for my ignorance but I'm new to all of this, do you mean add crew to the group by and order by clauses?
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-02-14 : 10:58:50
No, I mean add crew in the index.
Go to Top of Page

tc
Starting Member

11 Posts

Posted - 2006-02-14 : 11:04:26
I'm getting the data from a view.
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-02-14 : 11:16:46
Which is query based on one or more tables and you can create index on tables. You can even create index on view but it is too advanced topic at the moment for you. So run
sp_helptext viewCrewDataL1
and see if both histDate and crew come from the same table.
Go to Top of Page
   

- Advertisement -