title: Getting the value of a query into a parameter
body: <p>I'm trying to convert some of the SQL code we use in our projects towards using parameters. Inserting works fine:</p>
  
  <pre><code>with SQLDataSet do begin
    Close;
    SQL.Text := 'INSERT INTO testtable (keyname, waarde) VALUES (:keyname,:waarde)';
    Prepare;
    for i := 1 to 10000 do begin
      ParamByName('waarde').AsInteger := i;
      ParamByName('keyname').AsString := 'Testa'+IntToStr(i);
      ExecSql;
    end;
  end;
  </code></pre>
  
  <p>work fine and fast.</p>
  
  <p>But, I can't get it to work with select Statements.
  At first the following seems to work:</p>
  
  <pre><code>with SQLDataSet do begin
    SQL.Clear;
    SQL.Text := 'SELECT :waarde = waarde FROM testtable WHERE keyname = :keyname';
    Prepare;
    for i := 1 to 10000 do begin
      ParamByName('keyname').AsString := 'Testa'+IntToStr(i);
      ExecSQL;
      k[i] := ParamByName('waarde').AsInteger;
      Close;
    end;
  end;
  </code></pre>
  
  <p>but the value of k[i] just gets filled with 0's. Do I need to keep selecting the old fashioned way, issuing the query, opening and traversing the result set or is there a way when you have a query with only 1 row to select right into a parameter value? </p>