title: vfp query much faster in command window than compiled
body: <p>Here's my query:  </p>
  
  <pre><code>SELECT solGroup,;
         SUM(IIF((;
                  SELECT COUNT(*) FROM cgift c2;
                      WHERE c2.solgroup != c1.solgroup AND c1.donor == c2.donor;
                  ) &gt; 0;
             ,1,0));
          countgaveother;
      FROM cgift c1;
      GROUP BY solGroup
  </code></pre>
  
  <p>cGift is a cursor containing a list of records.</p>
  
  <pre><code>autonumber...donor....solGroup
  1............10.......a
  2............11.......a
  3............10.......b
  4............15.......b
  5............10.......c
  6............15.......c
  7............11.......d
  8............11.......d
  9............16.......d
  </code></pre>
  
  <p>The query generates the following</p>
  
  <pre><code>solGroup.."count of donors who have records with a different solgroup as well as this one"
  a..........2
  b..........2
  c..........2
  d..........1
  </code></pre>
  
  <p>There are about 80k records in cGift (and many more fields that are not used here). It takes 3 seconds to run this query (plus the one creating the cursor) from the vfp command window and 30 minutes to run from inside a compiled form.</p>
  
  <p>Anyone have any idea why the performance difference is so great? Normally the command window performs very similar to my compiled forms. Other queries run perfectly fine in this form as well.</p>
  
  <p>The cursor is created with a <code>select ... into cursor cGift</code>. It is ordered by donor, though removing this changes nothing.</p>
  
  <p>I'm on VFP 9 sp2. Anyone know how speed it up?</p>
  
  <p>EDIT:
  Ok, let me summarize and see if anyone else has any ideas.<br>
  I create a cursor with a <code>select into ... cursor cGift</code>.<br>
  Then I run the above query on said cursor.<br>
  It's fast in the command window but very slow when running from a form.<br>
  Exact same code for both cursor and query.<br>
  I have no idea what environment settings are on/off/wtvr in my form since it's part of a very large program.  </p>