...

View Full Version : Single Quotes give me a syntax error! -- Comment



Shift4Sms
08-04-2004, 07:37 PM
Whammy,

The Single Quotes give me a syntax error! (http://www.codingforums.com/forumdisplay.php?f=8) sticky thread is very informative but I would just make one tweak. I use a very similar technique except that I have the CSQ function include the outermost single quotes for me:


Function CSQ(byVal str)
If IsNull(str) Then
CSQ = "null"
Else
CSQ = "'" & Replace(str,"'","''") & "'"
End Function
Two reasons for this:


SQL = "INSERT INTO tablename (myvar, myvar2) VALUES (" & CSQ(myvar) & "," & CSQ(myvar2) & ')" is easier to read and less error prone to typing than
SQL = "INSERT INTO tablename (myvar, myvar2) VALUES ('" & CSQ(myvar) & "','" & CSQ(myvar2) & "')" (albeit only slightly with ASP -- with other languages the benefits of readability and reduction in typing is greater)

It allows for storing real null's in the database instead of ''


Hope this helps...

glenngv
08-05-2004, 06:12 AM
SQL = "INSERT INTO tablename (myvar, myvar2) VALUES (" & CSQ(myvar) & "," & CSQ(myvar2) & ')" is easier to read and less error prone to typing than ...

But you had a typo there. :p :D
You had a single quote instead of a double quote.

Shift4Sms
08-05-2004, 08:51 PM
But you had a typo there. :p :D
You had a single quote instead of a double quote.
Crap -- I did what I razz some of the programmers that work for me; the #1 Cardinal sin :eek: : I made a change without testing it.

:( :( :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum