title: Delphi SQL query
body: <p>I was wondering if you could take a look at my code for date comparison on Delphi. </p>
  
  <p>Code snippet in DELPHI:-</p>
  
  <pre><code>        // SQL QUERY to gather member information.
             DMS.ADOQuery1.SQL.Clear;
             DMS.ADOQuery1.SQL.Add('select HPFROMDT, HPthruDt, MEMBERKEY, MEMBHPKEY, OPFROMDT, OPTHRUDT, HPCODEKEY' +
                                   ' from MEMBHP' +
                                   ' where MEMBERKEY = ''' + MembKey + '''   and OPFROMDT &lt;= ''' + date_request + ''' and OPTHRUDT &gt; ''' + date_request +''' '
  </code></pre>
  
  <p>Script snippet in SQL:-</p>
  
  <pre><code>SELECT [MEMBHPKEY]
        ,[MEMBERKEY]
        ,[CURRHIST]
        ,[HPFROMDT]
        ,[OPFROMDT]
        ,[OPTHRUDT]
        ,[HPCODEKEY]
        ,[HPOPTIONKEY]
  
    FROM [main].[dbo].[*****]
  
    where MEMBERKEY = '1234567' and OPFROMDT &lt;= '2007-08-01' and OPTHRUDT &gt; '2007-08-01'
  </code></pre>
  
  <p>The SQL script obviously compares a constant date  value with the extracted date values. And it works!</p>
  
  <p>However, the Delphi code doesn’t work. The error message </p>
  
  <blockquote>
    <p><em>Conversion failed when converting character string to smalldatetime
    date type.</em></p>
  </blockquote>
  
  <p>I believe there has to be some kind of conversion technique for Delphi that should allow me to convert into the right variable type…. Any ideas?</p>
  
  <p>I extract <code>date_request</code> as a string variable from a text file....</p>
  
  <pre><code>  for i := 11 to length(buffer) do
                          begin
                               DT_request := DT_request + buffer[i];
                          end;
  </code></pre>