Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make WHERE statement

Status
Not open for further replies.

jurgenv89

Programmer
Apr 3, 2007
3
0
0
NL
Hi,

This may seem like a very noobish question. Maybe it is :)

Usually i use mysql databases, but i'm doing a special assignment in which i have to use odbc.

I have this query:

"SELECT * FROM `Calls_cal` WHERE calID='52' ORDER BY `calID`"

But it gives an error. I've read i should put calID in quotes, like WHERE 'calID'='52' But then it gives no results. I think quoting 'calID' means it just looks at the text 'calID', but i want it to see if the value of the column calID equals 52.

Who can help me?

Thanks in advance,

Jurgen
 



Hi,

Try this...
Code:
"SELECT * FROM `Calls_cal` WHERE `calID`='52' ORDER BY `calID`"
NOTE: This syntax is NOT identical
Code:
`calID`
'calID'
You could also use...
Code:
"SELECT * FROM [Calls_cal] WHERE [calID]='52' ORDER BY [calID]"




Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Nope that doesn't work. I think i have a weird kind of odbc installed :s
 
What is the ODBC-enabled application? MS Access?

What is the ODBC driver?

What is the schema of the table, especially the relevant columns?

Tom Morrison
 
The question was not posted by me but it answered one I just posted in PHP.

I am using Apache, PHP and through no fault of my own a remote MS Access database via odbc. I could not get the WHERE clause to work no how, no way. Both of your examples worked perfectly.

Thanks a million!

Ed
 
I spoke a bit too soon. It works until I try to use the WHERE with an ip address

This returns no rows, the address exists in 3 rows
Code:
"SELECT user_name, host_name, ip_address from [log] where [ip_address] = '192.160.12.15'";
 



...and the data is EXACTLY the same as 192.160.12.15, no trailing spaces or anything?

try
Code:
"SELECT user_name, host_name, ip_address from [log] where [b]trim([/b][ip_address][b])[/b] = '192.160.12.15'[b];[/b]"

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Well, no it was not exact. I had a O (oh) in my query instead of a 0 (zero). (head hung in shame)

Backtracking through all the messages enclosing the table and where criteria in either []'s or ``'s did the trick.

Had I not switched my editor to the andale mono (fixed pitch, zero slash) after your EXACTLY message I would still be looking.

Thanks for both your patience and assistance.

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top