Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Las Vegas, NV - USA
    Posts
    104
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Single Quotes give me a syntax error! -- Comment

    Whammy,

    The Single Quotes give me a syntax error! 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:

    Code:
    Function CSQ(byVal str)
        If IsNull(str) Then
            CSQ = "null"
        Else
            CSQ = "'" & Replace(str,"'","''") & "'"
    End Function
    Two reasons for this:
    1. Code:
      SQL = "INSERT INTO tablename (myvar, myvar2) VALUES (" & CSQ(myvar) & "," & CSQ(myvar2) & ')"
      is easier to read and less error prone to typing than
      Code:
      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)
    2. It allows for storing real null's in the database instead of ''


    Hope this helps...
    Steven Sommers (blog)
    Shift4 Corporation -- www.shift4.com

    Creators of $$$ ON THE NET(tm) payment processing services.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    Quote Originally Posted by Shift4Sms
    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.
    You had a single quote instead of a double quote.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Las Vegas, NV - USA
    Posts
    104
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Quote Originally Posted by glenngv
    But you had a typo there.
    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 : I made a change without testing it.



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •