when I insert table, value is a string contains apostrophe - it throws an error there

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvnaidu
    Contributor
    • Oct 2009
    • 365

    when I insert table, value is a string contains apostrophe - it throws an error there

    When I do INSERT like below, value is a string with apastrophe (for ex: "Checking for 'hlt' instruction"), insert throws an error - how to fix?

    INSERT INTO table_name (column1, column2, column3,...)
    VALUES (value1, value2, value3,...)
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Remove those quotes. If you need, replace it with something else. Then replace it back when you're retrieving it.

    Happy Coding!!!

    ~~ CK

    Comment

    • JonathanVH
      New Member
      • Feb 2010
      • 2

      #3
      This should only be an issue if you're using string literals in a script, in which case you can double the single quotes in the string, e.g.:
      Code:
      INSERT dbo.table_name(column1)
      VALUES('Checking for ''hit'' instruction');
      Based on your using double quotes around the value and calling its data type a "string," I infer that this value is coming from your front-end programming language, in which case you should use parameterized commands, be they text or stored procedures, as that will both obviate such issues and guard against SQL injection attacks.

      Comment

      • tvnaidu
        Contributor
        • Oct 2009
        • 365

        #4
        Thanks, actually this is using lua script, I found an escape sequence to do that, I fixed this. thanks.

        Comment

        Working...