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.
Author |
Topic |
sagitariusmzi
Posting Yak Master
113 Posts |
Posted - 2009-11-16 : 06:50:42
|
Hi,How to speed up this QuerySELECT DISTINCT YEAR(vch_date) FROM VoucherThanks |
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-11-16 : 12:32:42
|
how many rows in the table? I'm assuming this is doing a table or clustered index scan on you since you're using a function. How about a computed column on the table that holds the year. Index the column, see how it goes. You might also try group by instead of distinct. not sure if that would make a difference, you'd have to check the query plan.Mike"oh, that monkey is going to pay" |
 |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-16 : 13:32:24
|
quote: Originally posted by mfemenel how many rows in the table? I'm assuming this is doing a table or clustered index scan on you since you're using a function. How about a computed column on the table that holds the year. Index the column, see how it goes. You might also try group by instead of distinct. not sure if that would make a difference, you'd have to check the query plan.Mike"oh, that monkey is going to pay"
Well is there an index on vch_date????Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
Pradip
Starting Member
32 Posts |
Posted - 2009-11-17 : 05:51:44
|
Mike, I think Computed column will be better solution, but indexing computed column will not make much difference as same years will repeat no of times, as it is voucher table. also one can try group by but I think will not make any difference.www.silicus.compradipjain |
 |
|
sagitariusmzi
Posting Yak Master
113 Posts |
Posted - 2009-11-17 : 06:32:01
|
The query gives this result200120022003200520042006200720092008Yes there is an index on vch_date. |
 |
|
|
|
|