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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help needed with SQL

Help needed with SQL

Scheduled Pinned Locked Moved Visual Basic
helpdatabasetutorial
5 Posts 5 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.
  • D Offline
    D Offline
    damian martin
    wrote on last edited by
    #1

    Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated

    G L M 3 Replies Last reply
    0
    • D damian martin

      Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated

      G Offline
      G Offline
      Guillermo Rivero
      wrote on last edited by
      #2

      Use 2 '' instead... "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian''s computer" Free your mind...

      1 Reply Last reply
      0
      • D damian martin

        Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I usually creates a function PadApostrophe(strText as string) which will replace every single instance of ' with '' (two single quotes). But recently I read this is not a very good way to do it, so if you're using SQL command object you can pass parameters instead and you don't need to replace the '. Hope this helps! :)

        B 1 Reply Last reply
        0
        • L Lost User

          I usually creates a function PadApostrophe(strText as string) which will replace every single instance of ' with '' (two single quotes). But recently I read this is not a very good way to do it, so if you're using SQL command object you can pass parameters instead and you don't need to replace the '. Hope this helps! :)

          B Offline
          B Offline
          Bo Hunter
          wrote on last edited by
          #4

          Amen

          1 Reply Last reply
          0
          • D damian martin

            Can anyone help. I am trying to create an SQL statment and in the WHERE clause the text being searched for has a ' in. For example "SELECT * FROM [computer list table] WHERE [Computer Owner] = Damian's computer" The problem i am having is with the Damian's Computer. It seems to get upset with the ' Any help would be much appreciated

            M Offline
            M Offline
            MikeAngelastro
            wrote on last edited by
            #5

            Here is what I do. I create a constant called QUOTES as below. Const QUOTES = """" I then create a function called SQLstring as below. Public Function SQLstring(StringIn as String)as String SQLstring = QUOTES & StringIn & QUOTES End Function So now if I want write an SQL statement that needs a string within a string, I do the following: Dim SQL as String Dim State as String State = "CA" SQL = "SELECT * FROM Table WHERE State = " & SQLstring(State) The resulting SQL will be as follows: SELECT * FROM Table WHERE State = "CA" Is this what you are looking for?

            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