Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. GenericOLEDB - how to insert string var with single quote in value?

GenericOLEDB - how to insert string var with single quote in value?

Scheduled Pinned Locked Moved Database
tutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rick at abc
    wrote on last edited by
    #1

    Using the sample GenericOLEDB how can you insert a string that has a single quote in the text of a string var? insert into SOMETABLE ([SOMEFIELD]) VALUES ('Bob's');

    L I N 3 Replies Last reply
    0
    • R rick at abc

      Using the sample GenericOLEDB how can you insert a string that has a single quote in the text of a string var? insert into SOMETABLE ([SOMEFIELD]) VALUES ('Bob's');

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Google SQL literal string, to find the documentation[^]: When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers. For more information, see Identifiers. Literals can be delimited by either single or double quotation marks. And of course, if the SQL statement is itself a string literal (e.g. in C#) then you must escape all double quotes with a preceding backslash. :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      1 Reply Last reply
      0
      • R rick at abc

        Using the sample GenericOLEDB how can you insert a string that has a single quote in the text of a string var? insert into SOMETABLE ([SOMEFIELD]) VALUES ('Bob's');

        I Offline
        I Offline
        i j russell
        wrote on last edited by
        #3

        insert into SOMETABLE ([SOMEFIELD]) VALUES ('Bob''s'); Two single quotes '' not a double quote ".

        1 Reply Last reply
        0
        • R rick at abc

          Using the sample GenericOLEDB how can you insert a string that has a single quote in the text of a string var? insert into SOMETABLE ([SOMEFIELD]) VALUES ('Bob's');

          N Offline
          N Offline
          Niladri_Biswas
          wrote on last edited by
          #4

          Try this

          declare @tbl table(SomeField varchar(50))
          insert into @tbl(SomeField) values('Bob''s')
          select * from @tbl

          Output: SomeField

          Bob's

          Instead of 'Bob's' write 'Bob'**'**s'. Hope this helps :)

          Niladri Biswas

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups