My Query is: select Partnumber, min(convert(varchar(10), b.requestdatetime, 101)) as [DownloadDate], convert(varchar(10), purchase_date, 101) as [PurchaseDate], Invoice, Quantity, convert(money, NetPrice) as [NetPrice], convert(money, Totalsalenet) as [TotalSales] from sales_history a join smc_new_products.dbo.etechmodelrequests b on RTrim(a.partnumber) = substring(b.configname, 0, (Len(a.partnumber) + 1)) where purchase_date between '04/01/2001' and '03/31/2002' and accountnumber in (select accountnumber from sales_company where company_name like'ABBOTT LABORATORIES (IL)') and (family like '%') group by partnumber, convert(varchar(10), purchase_date, 101), invoice, quantity, convert(money, NetPrice), convert(money, Totalsalenet) order by TotalSales desc
The Sales History table has several million records. The etechmodelrequests table has a couple of hundred-thousand. They are in two different databases to make matters worse. Right now this query is taking forever. When I remove the Join and don't get any info from the etechmodelrequests table, the query runs in 11 seconds. Any suggestions are much appreciated as always.