We help IT Professionals succeed at work.
Get Started

SQL Server Script Times Out

275 Views
Last Modified: 2012-05-07
This script will run with no syntactical errors, but it runs a long time, then stops with no result set. The only error message I get is 'Object was open'.  The problem arose when I added the INNER JOIN line.  Without the INNER JOIN, the script runs quickly and completes with the correct result set.  How can the script be modified to perform the INNER JOIN without dragging the rest of the script's performance down and stopping script execution before a result set can be generated?


SELECT CASE 
         WHEN apitem.fcpocat = 'JO' 
         THEN Left(apitem.fcsojokey,5) 
         ELSE '' 
       END AS 'JO#', 
       CASE 
         WHEN apitem.fcpocat = 'SO' 
         THEN Left(apitem.fcsojokey,6) 
         ELSE '' 
       END AS 'SO#', 
       apitem.fcsojokey, 
       apitem.fcpocat, 
       Left(apitem.fpokey,6)   AS pokey, 
       Left(apitem.frecvkey,6) AS rcvkey, 
       apitem.finvqty, 
       apitem.fpartno, 
       apitem.fvucost, 
       apitem.fvptdes,
       apitem.fcinvkey,
       apmast.fccompany,
       apmast.fvendno, 
       apitem.identity_column 
FROM   apitem
INNER JOIN apmast on left(apitem.fcinvkey,6) = apmast.fvendno 
WHERE  apitem.fcpocat IN ('JO','SO')

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE