Help needed with SQL
-
Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated
-
Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated
Use 2 '' instead...
"SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian''s computer"
Free your mind... -
Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated
I usually creates a function PadApostrophe(strText as string) which will replace every single instance of ' with '' (two single quotes). But recently I read this is not a very good way to do it, so if you're using SQL command object you can pass parameters instead and you don't need to replace the '. Hope this helps! :)
-
I usually creates a function PadApostrophe(strText as string) which will replace every single instance of ' with '' (two single quotes). But recently I read this is not a very good way to do it, so if you're using SQL command object you can pass parameters instead and you don't need to replace the '. Hope this helps! :)
-
Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated
Here is what I do. I create a constant called QUOTES as below. Const QUOTES = """" I then create a function called SQLstring as below. Public Function SQLstring(StringIn as String)as String SQLstring = QUOTES & StringIn & QUOTES End Function So now if I want write an SQL statement that needs a string within a string, I do the following: Dim SQL as String Dim State as String State = "CA" SQL = "SELECT * FROM Table WHERE State = " & SQLstring(State) The resulting SQL will be as follows: SELECT * FROM Table WHERE State = "CA" Is this what you are looking for?