PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

SQL Proboblem/Bug

How would you run a WHERE on 17' monitors?
LIKE SELECT * FROM tblTable WHERE fldPRoducts = '17' monitors' SQL doesnt likt the single quaote. Is there an escape sequence like \' or something?
&' i think...
Did you try double quotes?

"17' Monitor"

Depends on the implimentation of SQL, and I never tried it on a PPC.
Ok heres the deal &' doesnt work i get this error

Query:
select * from CCIProducts where pdctProductCode LIKE '&''

Error:
Server: Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark before the character string '&'
'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '&'
'.

I tried to use double quotes with  the where attribute and it didnt work

Query:
select * from CCIProducts where pdctProductCode LIKE "memory"

Error:
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'memory'.

I am using Microsoft SQL server 7.0 with Visual Basic and ADO, This has nothing to do with the ppc RICoder. I ran all thoughs Querys in the SQL Quey Analizyer to make sure there was no middle man problem with VB and ADO.

So does anyone know how to do a querly like

SELECT * FROM CCIProducts WHERE pdctProductCode = '17' monitor'

The problem is sql thinks im termanating my query at the ' after 17. I know there has to be a way of doing this i just dont know how.

Any help would be qreatly appriciated becuase this is for my job, thanks. :)
ADO is funky like that.  Mostly it requires strict adherence to STANDARD SQL.  Meaning that you need to do stuff like using % as a wild card, even though some DBs use *.  But, in other cases it doesn't care what you do, like you can use a terminating ; in the statement, even though only Access (that I know of) lets you do that.  This is all fluff, but I wrote it anyway.

My point is, I guess, that standard SQL uses ' as string literal containers, NOT ".  In fact the " will raise an error in some cases in ADO.  It ALWAYS did for me when I tried to write some test code.

I don't know if there are any escape sequences in SQL...and I won't be in my office to ask our resident SQL guru until Thurs...If you still want to know then, let me know.
ok, ill let you know i think i may be talking to a guy today.
Try two single quotes e.g. ''  That works on 'Big' SQL
Right,

I found the function I wrote for sorting out these problems.

It only works for SELECT type queries, not INSERT's

Code:

Function SQLEncode(InputString)
     Dim TempString
     Dim ReturnString
     TempString = InputString
     If NOT TempString = "" Then
           ReturnString = TempString
           ReturnString = replace(ReturnString,"'","''")
           ReturnString = replace(ReturnString,"*","[*]")
           ReturnString = replace(ReturnString,"?","[?]")
           ReturnString = replace(ReturnString,"#","[#]")
           ReturnString = replace(ReturnString,"[","[[]")
           ReturnString = replace(ReturnString,"-","[-]")
     Else
           ReturnString = ""
     End If
     SQLEncode = ReturnString
End Function



The main bit you want is replacing a single quote with 2 single quotes, but the other delimiters may be handy..
Sorry, I forgot to turn smileys off, and im not registered, so I cant edit my post.

Lets try again:

Code:

Function SQLEncode(InputString)
     Dim TempString
     Dim ReturnString
     TempString = InputString
     If NOT TempString = "" Then
           ReturnString = TempString
           ReturnString = replace(ReturnString,"'","''")
           ReturnString = replace(ReturnString,"*","[*]")
           ReturnString = replace(ReturnString,"?","[?]")
           ReturnString = replace(ReturnString,"#","[#]")
           ReturnString = replace(ReturnString,"[","[[]")
           ReturnString = replace(ReturnString,"-","[-]")
     Else
           ReturnString = ""
     End If
     SQLEncode = ReturnString
End Function

Grrr, I give up!

You should be able to get the idea anyways..
hehe, me again! :)

The line
Code:
ReturnString = replace(ReturnString,"[","[[]")


should be the first of the replace statements..
thanks