المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : SQL select on two tables takes too long



C# Programming
02-11-2010, 08:54 AM
I have two tables on a database where I need to gather information for a report. I have built a select statement and run it through an Odbc.DataReader. Stepping through the debugger, once ExecuteReader is executed the program stalls, for a period of minutes. Is there anyway to make this select statement more efficient?

The fields that start with INV are in the NINVREC table. The fields that start with MISCITEM are in the MISCITEM table.
The matching keys are MISCITEM-SERIAL-NBR and INV-MK-SERIAL-NBR.

The database is read only.

OdbcDataReader DbReader;
OdbcConnection DbConnection = new OdbcConnection("DSN=rsss");
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "SELECT MISCITEM-DATE, MISCITEM-SERIAL-NBR, INV-MK-SERIAL-NBR, MISCITEM-MODEL-NBR, MISCITEM-CUST-ACCT-NBR, MISCITEM-EXCHANGE-MODEL-NBR, " +
" INV-SELL-PRICE,INV-ORIGINAL-COST, MISCITEM-ACTUAL-COST, MISCITEM-SALESMAN-1, MISCITEM-TICKET-NBR, MISCITEM-STORE FROM MISCITEM " +
" INNER JOIN NINVREC ON MISCITEM-SERIAL-NBR=INV-MK-SERIAL-NBR " +
" WHERE (MISCITEM-DATE >= '" + strEOMDate + "<span class="code-string">' AND MISCITEM-DATE