Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic SQL (2003 (SP2))

    I'm trying to create a dynamic pass-through query, where the user can set between parameters on a form.

    I've managed to code the query, without the form input, but now I'm a little stuck; keep getting ODBC failure errors.

    Here's where I'm at;

    Edit;
    Silly me, didn't declare variable. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    Anyway, still not got it. Here's the next version

    SQLString = "SELECT "
    SQLString = SQLString & "ORDNO,BEMSCD as Press,G7FZKD as Code,G3E0TX as Desc,"
    SQLString = SQLString & " G7ARCD as OpCode, G7IOPQ as Wgt, G7ALDT as Date, BEFEPN As TotalNtWgt "
    SQLString = SQLString & "From EISGBRQRY.KL_SCRAP Where G7IOPQ >= 200 And (G7ALDT between 1060101 and "
    SQLString = SQLString & "strDateTo) "
    SQLString = SQLString & "Order by G7ALDT DESC"
    MyQueryDef.Connect = ConnectString

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic SQL (2003 (SP2))

    Is strDateTo a variable in your code? If so, change
    <code>
    SQLString = SQLString & "strDateTo) "
    </code>
    to
    <code>
    SQLString = SQLString & strDateTo & ") "
    </code>
    Note that strDateTo has been moved outside the quotes, so that the value of strDateTo will be concatenated into SQLString instead of the name strDateTo.

  3. #3
    4 Star Lounger
    Join Date
    May 2001
    Location
    Oxfordshire
    Posts
    456
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic SQL (2003 (SP2))

    Oop, you beat me; I got it to work. Though your solution is better. Cheers

    BTW here's what I ended with
    SQLString = SQLString & "" & strDateTo & ") "

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •