I have a query that needs to return only if there are records that
match the criteria. My current query is something like this:
SELECT MAX(RECORD_DATE),RECORD_NAME
FROM TABLE_NAME
WHERE RECORD_DATE >= '7/21/2008' /*Today's Date*/
GROUP BY RECORD_NAME
The problem is that there can be thousands of records. The query can
often time out. And all I need to know is if there are any records. If
there is even one that's all I need to know.
Could somebody help me with this one?
tod
Denisio - 22 Jul 2008 06:50 GMT
Information is not full. Do you have indexes? How many records in table? What
is table structure? Do you have primary key on table? Which columns used as
primary key? What is server version? I think what you can create index with
next statement:
create index IX_1 on TABLE_NAME (RECORD_DATE, RECORD_NAME)
// if you have SQL 2000/2005/2008
or
create index IX_1 on TABLE_NAME (RECORD_DATE) include (RECORD_NAME)
// if you have SQL 2005/2008.
Also, I preferred create primary key on each table in database. Please check
existence of primary key in you table.
Sorry for bad English.