Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Need Ideas for SQL Query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
todtown - 21 Jul 2008 20:56 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.