Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-11-2007, 05:47 PM   PM User | #1
mdwebster
New to the CF scene

 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
mdwebster is an unknown quantity at this point
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
mdwebster is offline   Reply With Quote
Old 05-11-2007, 06:12 PM   PM User | #2
Daemonspyre
Regular Coder

 
Join Date: Mar 2007
Posts: 505
Thanks: 1
Thanked 19 Times in 19 Posts
Daemonspyre is on a distinguished road
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
Daemonspyre is offline   Reply With Quote
Old 05-14-2007, 09:42 AM   PM User | #3
mdwebster
New to the CF scene

 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
mdwebster is an unknown quantity at this point
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.
mdwebster is offline   Reply With Quote
Old 05-14-2007, 01:45 PM   PM User | #4
Daemonspyre
Regular Coder

 
Join Date: Mar 2007
Posts: 505
Thanks: 1
Thanked 19 Times in 19 Posts
Daemonspyre is on a distinguished road
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!
Daemonspyre is offline   Reply With Quote
Old 05-15-2007, 07:58 PM   PM User | #5
ghell
Senior Coder

 
Join Date: Apr 2003
Location: England
Posts: 1,192
Thanks: 5
Thanked 13 Times in 13 Posts
ghell is on a distinguished road
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 #
__________________
My tech/code blog
ghell is offline   Reply With Quote
Old 05-16-2007, 02:34 PM   PM User | #6
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
What database are you using?
What is the field data type?
degsy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 AM.


Advertisement
Log in to turn off these ads.