SQL Statement looping

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL Statement looping



    Trying to pull a report from an access 2k database that grabs the top 5
    records for each day in a range (inputed by user). Yes, I know that the
    * character is not a good idea, but I put it here for brevity.

    Here is my SQL Statement:

    LTQry = "SELECT TOP 5 * FROM History " & _
    "WHERE Calendar = '" & tmpDte & "'"

    Here is my code:

    Do until tmpDte > rEndDte
    Set RsTstOtpt = OBJdbConn.Execute(LTQry)
    Do While Not RsTstOtpt.EOF
    %>
    <table>
    <tr>
    <td>
    <%=RsTstOtpt("Event") %>
    </td>
    <td>
    <%=RsTstOtpt("CustName") %>
    </td>
    <td>
    <%=RsTstOtpt("Calendar") %>
    </td>
    <td>
    <%=RsTstOtpt("History") %>
    </td>
    </tr>
    </table>
    <%
    RsTstOtpt.MoveNext
    Loop
    RsTstOtpt.Close
    Set RsTstOtpt = Nothing
    tmpDte = DateAdd("d",1,tmpDte)
    Loop

    Here is the error message:
    Microsoft JET Database Engine (0x80040E07)
    Data type mismatch in criteria expression.
    (in line where the SQL statement is executed)


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    PorkyJr Guest

  2. Similar Questions and Discussions

    1. Looping
      For some reason the dept names are randomly out putting twice on the outer loop. Does anyone know why this might be happening. Code: <CFQUERY...
    2. Looping .....Help!
      HI i want to publish a swf file that only loops 3 times and it has to be published version 5. Anyone have a sneaky piece of code for lopping a fixed...
    3. XML and looping
      Hey guys, I have a XML file as follows: <book> <Name>I Have a Dream</Name> <Price>3.00</Price> <Description>This is a great...
    4. Looping SWF
      Oh yeah, I should mention that I am on Dir7! :)
    5. Looping or what?
      The code below is suppose to replace some images and links but when I run it the page just seems to hang and eventually times out. Am I Looping...
  3. #2

    Default Re: SQL Statement looping

    Dates are delimited with # instead of ' in Access.

    Ray at work

    "PorkyJr" <nospam@nospam.net> wrote in message
    news:%23RGHda%23zDHA.2328@TK2MSFTNGP10.phx.gbl...
    >
    >
    > Trying to pull a report from an access 2k database
    >
    > Here is my SQL Statement:
    >
    > LTQry = "SELECT TOP 5 * FROM History " & _
    > "WHERE Calendar = '" & tmpDte & "'"
    >
    >
    > Here is the error message:
    > Microsoft JET Database Engine (0x80040E07)
    > Data type mismatch in criteria expression.

    Ray at Guest

  4. #3

    Default Re: SQL Statement looping

    On Wed, 31 Dec 2003 13:39:46 -0800, PorkyJr <nospam@nospam.net> wrote:
    >Trying to pull a report from an access 2k database that grabs the top 5
    >records for each day in a range (inputed by user). Yes, I know that the
    >* character is not a good idea, but I put it here for brevity.
    >
    >Here is my SQL Statement:
    >
    >LTQry = "SELECT TOP 5 * FROM History " & _
    > "WHERE Calendar = '" & tmpDte & "'"
    >
    >Here is my code:
    >
    >Do until tmpDte > rEndDte
    >Set RsTstOtpt = OBJdbConn.Execute(LTQry)
    >Do While Not RsTstOtpt.EOF
    >%>
    ><table>
    ><tr>
    ><td>
    ><%=RsTstOtpt("Event") %>
    ></td>
    ><td>
    ><%=RsTstOtpt("CustName") %>
    ></td>
    ><td>
    ><%=RsTstOtpt("Calendar") %>
    ></td>
    ><td>
    ><%=RsTstOtpt("History") %>
    ></td>
    ></tr>
    ></table>
    ><%
    >RsTstOtpt.MoveNext
    >Loop
    >RsTstOtpt.Close
    >Set RsTstOtpt = Nothing
    >tmpDte = DateAdd("d",1,tmpDte)
    >Loop
    >
    >Here is the error message:
    >Microsoft JET Database Engine (0x80040E07)
    >Data type mismatch in criteria expression.
    >(in line where the SQL statement is executed)
    First, do a Response.Write LTQry and make sure you're getting the
    query as you expected. Best guess is you have a date type versus
    string type issue in your tmpDte. What type does your database use?

    Jeff
    Jeff Cochran Guest

  5. #4

    Default Re: SQL Statement looping


    Did a response.write LTQry and it is looping as expected; however it is
    not inserting the value of variable tmpDte. It doesn't matter if I use
    the ' or # or ().

    Thoughts?


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    PorkyJr Guest

  6. #5

    Default Re: SQL Statement looping

    Can you post your Response.Write of LTQry?

    Ray at work

    "PorkyJr" <nospam@nospam.net> wrote in message
    news:O8MMqaU0DHA.2156@TK2MSFTNGP12.phx.gbl...
    >
    > Did a response.write LTQry and it is looping as expected; however it is
    > not inserting the value of variable tmpDte. It doesn't matter if I use
    > the ' or # or ().
    >
    > Thoughts?
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Ray at Guest

  7. #6

    Default Re: SQL Statement looping


    Sorry, figured it out. Just had my SQL statement in the wrong place in
    the code. Works like a champ when I put the SQL statement inside the
    loop.



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    PorkyJr Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139