|
-
Mar 4th, 2003, 01:51 PM
#1
Thread Starter
Frenzied Member
SQL Query question
Can anyone tell me why this sql string gives me an error?
VB Code:
"SELECT * FROM WorkOrders WHERE CustomerRefNumber = 'MM-0000001' AND JobCompleted = '1'"
I am using a MSA 2000 db and ADO.
I get an error of "Data type mismatch"
Thanks,
Rudy -
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 01:53 PM
#2
Fanatic Member
maybe because the [JobCompleted] field is declared as some sort of numeric in the database. if it is, take off the quotes around the value:
VB Code:
"SELECT * FROM WorkOrders WHERE CustomerRefNumber = 'MM-0000001' AND JobCompleted = 1"
-
Mar 4th, 2003, 01:55 PM
#3
Thread Starter
Frenzied Member
The jobcompleted field is a checkbox. I have tried it with a 0 (=false) and a False parameter. I get the same error...
Confusing...
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 01:59 PM
#4
Fanatic Member
i'm affraid i dont get the idea then. when you submit the query, you have to put in the name of the field as it is declared in the database (the 'column' name), not the name of the checkbox...
-
Mar 4th, 2003, 02:03 PM
#5
Thread Starter
Frenzied Member
Yea. "JobCompleted" is the field. Its datatype is a checkbox (yes/no).
This is the sql generated by MSA
SELECT *
FROM WorkOrders
WHERE (((WorkOrders.CustomerRefNumber)="MM-0000001") AND ((WorkOrders.JobCompleted)=True));
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 08:01 PM
#6
Thread Starter
Frenzied Member
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 08:13 PM
#7
Thread Starter
Frenzied Member
I think it is how I am using the "AND" to select based on 2 different values. Can someone verify that the SQL string is correct?
Thanks,
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 08:17 PM
#8
-
Mar 4th, 2003, 08:33 PM
#9
Thread Starter
Frenzied Member
-
Mar 4th, 2003, 08:34 PM
#10
-
Mar 4th, 2003, 08:45 PM
#11
Thread Starter
Frenzied Member
CustomerRefNumber is a String.
JobCompleted is Yes/No.
I tried it with just CustomerRefNumber and it works fine.
VB Code:
SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "'"
Then I tried these and they didn't work...
VB Code:
"SELECT * FROM WorkOrders WHERE JobCompleted = '0'"
and
"SELECT * FROM WorkOrders WHERE JobCompleted = '1'"
and
"SELECT * FROM WorkOrders WHERE JobCompleted = '-1'"
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 08:56 PM
#12
Thread Starter
Frenzied Member
GOT IT! Wew, finally..
The key is the "True" statement.. I hade 'True' and it needed to be True without the quotes....
VB Code:
"SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "' AND JobCompleted = True"
This a new one to me.... I think. I don't remember ever having this problem before..
Oh-well Thank to Mc Brain and Radum for the help..
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 09:02 PM
#13
Thread Starter
Frenzied Member
I am getting even more confused...
It seems that I can only have the quotes around the first value..
VB Code:
"SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "' AND Status = " & WorkOrderStatus & " AND JobCompleted = True "
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 09:02 PM
#14
Fanatic Member
aw jeez... isnt it funny how each sql dialect loves to mess around with the syntax for these boolean values... a couple of years ago i spent a few good days to figure out a syntax like
when running a sql statement a foxpro database
-
Mar 4th, 2003, 10:19 PM
#15
Thread Starter
Frenzied Member
So let me get this straight..
Time/Date fields are souronded by ##
String/Number fields are souronded by ''
Boolean/True-False as souronded by ..
What else?
Is this an ADO thing? I Never had this problem with RDO...
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 4th, 2003, 10:30 PM
#16
Fanatic Member
sorry tom dissapoint you, but honestly i dont know all the syntax combinations myself either. that thing with dots works for the foxpro odbc driver, but i doubt it works for something else. im almost sure it doesnt work for ms access in fact. i only worked with sql lately, so trust anybody else giving answers on that. i kinda bailed out of the thread at the point i saw other answers for you...
-
Mar 4th, 2003, 10:35 PM
#17
Need-a-life Member
Originally posted by RudyL
So let me get this straight..
Time/Date fields are souronded by ##
String/Number fields are souronded by ''
Boolean/True-False as souronded by ..
What else?
Is this an ADO thing? I Never had this problem with RDO...
Rudy
Number fields should not be surrounded at all.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 4th, 2003, 10:58 PM
#18
Addicted Member
IN ACCESS,
Time/Date fields are souronded by ##
String/Number fields are souronded by ''
Boolean/True-False as souronded by ..
IN MYSQL
Time/Date fields are souronded by ''
String/Number fields are souronded by ''
Boolean/True-False as souronded by ..
-
Mar 4th, 2003, 11:11 PM
#19
Lively Member
If it's a string, wrap single quotes around it. If it's a number, don't use quotes. If it is a boolean value, pass it in as a number (True = 1, False = 0) with no quotes around it.
Passing in True or False will work against an Access database, but not against many others. SQL Server requires it ot be 1 or 0.
Don't forget that CInt(True) in VB6 returns -1, not 1, so you might want to use Abs(CInt(BooleanVariable)) to make sure it works.
- gaffa
-
Mar 4th, 2003, 11:20 PM
#20
Need-a-life Member
Originally posted by gaffa
...
Don't forget that CInt(True) in VB6 returns -1, not 1, so you might want to use Abs(CInt(BooleanVariable)) to make sure it works.
Or just
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Mar 4th, 2003, 11:38 PM
#21
Thread Starter
Frenzied Member
Thanks alot for all the help.. and info.
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|