SQL Select Problem

johnuk4

Active member
Joined
Feb 18, 2006
Messages
25
Programming Experience
Beginner
Hi,
Sorry if this is a tad trivial however my knowledge of sql is fairly basic. The problem is with the following select statement, i'm not quite sure how to search for the string "212". I know that it is just a matter of having the quotations in the right place, but i cannot seem to work this out.
I am using vb.net with an access database
VB.NET:
        SQLStr = "SELECT Hardware_Problems.Hardware_Problem_Id, Hardware.Hardware_Type, Hardware.Hardware_Make, Hardware.Hardware_Model, Hardware_Problems.Date_Time, Hardware_Problems.Staff_Reported, Hardware_Problems.Problem_Description, Hardware_Problems.Location, Hardware_Problems.Resolve_Flag FROM Hardware INNER JOIN Hardware_Problems ON Hardware.Hardware_Id = Hardware_Problems.Hardware_Id WHERE (((Hardware_Problems.Location)= "212"));"
Thanks in advanced
Johnuk4
 
hangon, which of the following chunks of text, in bold, do you want to search for:


212

"212"



it depends on the db youre using. i use oracle so to search for a string with quotes round i do:

select * from table where column = '"212"'

because oracle uses single ' quotes for strings

typically in MS/oracle when you want to search for a text delimiter it's a double version of the delimiter, so if i wanted to find the text o'clock in oracle it would be:

select *f romt able where column = 'o''clock'

notes that is two ' ' not a single "


-

so for you it may be select * from table where column = """212"""
 
Even better would be a parameterized query... in my ADO.NET tutorial, pt 2... there's an example on how to do that.

Basically, you replace the 2121 in your where clause (with OUT quotes of any kind) with a place holder. Then using the command object, you add parameters to the query, giving the values for each parameter. Then you can execute the query and get the results.

-tg
 
agree.. except there is nothing in the question that indicates that the "212" is variable? :)
 
Point taken, I assumed 212 was a control value to test if things are working. Even still with a hard coded value, there's nothing wrong with parameterized queries... especialy if you want to test for O'Brian... :)

-tg
 
Back
Top