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...
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...