Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry ASP Help! mismatch error

    Trying to display all the records where printdate is between variables first date and last date but get 'Data type mismatch in criteria expression' - please help im going nuts!


    strSQL = "SELECT * FROM tbl_jobs WHERE accounthandler='" & "DT" & "' AND type='" & "Press" & "' AND printdate>='" & firstdate & "' AND printdate<='" & lastdate & "'

    objRS.Open strSQL, objconn

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    1) You are missing a last double quote on the end

    2) Are DT and Press variables or constants? If they are constants, then you don't need to add them using concatenates.

    Code:
    strSQL = "SELECT * FROM tbl_jobs WHERE accounthandler='DT' AND type='Press' AND printdate>='" & firstdate & "' AND printdate<='" & lastdate & "'"
    
    objRS.Open strSQL, objconn

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Daemonspyre View Post
    1) You are missing a last double quote on the end

    2) Are DT and Press variables or constants? If they are constants, then you don't need to add them using concatenates.

    Code:
    strSQL = "SELECT * FROM tbl_jobs WHERE accounthandler='DT' AND type='Press' AND printdate>='" & firstdate & "' AND printdate<='" & lastdate & "'"
    
    objRS.Open strSQL, objconn
    The statement does have a double quote on the end

    strSQL = "SELECT * FROM tbl_jobs WHERE accounthandler='DT' AND type='Press' AND printdate>='" & firstdate & "' AND printdate<='" & lastdate & " ' "

    and still returns the error. firstdate + lastdate are variables.

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    In your original post, it didn't. Sorry about that!

    Instead of doing a objRS.Open, do a

    response.write strSQL
    response.flush

    Look at your SQL statement. That will help you debug. It may be that you are firstdate and/or lastdate are not returning as dates that your DB likes.

    HTH!

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    You could also try using CDate() to make sure that they are valid dates and FormatDateTime to make sure that if they are dates they are in the correct format.

    Should all the things you have in 's be in 's? If it is a number or whatever it shouldnt be. Dates can be in ' or #

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What database are you using?
    What is the field data type?


  •  

    Posting Permissions

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