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. Database & SysAdmin
  3. Database
  4. Dealing with apostrophe in stored procedure

Dealing with apostrophe in stored procedure

Scheduled Pinned Locked Moved Database
databasehelp
8 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.
  • B Offline
    B Offline
    berba
    wrote on last edited by
    #1

    When a variable in my stored procedure contains an apostrophe, it returns me an error. I've tried the function REPLACE() but no luck. waiting for your suggesions. Thanks

    L C T B 4 Replies Last reply
    0
    • B berba

      When a variable in my stored procedure contains an apostrophe, it returns me an error. I've tried the function REPLACE() but no luck. waiting for your suggesions. Thanks

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

      berba wrote:

      I've tried the function REPLACE() but no luck.

      waiting for your suggesions.

      I suggest you post the error-message that you got when you tried that function, or the code that you tried.

      I are Troll :suss:

      1 Reply Last reply
      0
      • B berba

        When a variable in my stored procedure contains an apostrophe, it returns me an error. I've tried the function REPLACE() but no luck. waiting for your suggesions. Thanks

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #3

        Without seeing the code that uses the variable and how the variable is applied to the code, it's difficult to know what is happening. And also knowing what the error return is will help out as well. Just a guess, but usually embedded apostrophes within strings will need to be escaped somehow. :)

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        1 Reply Last reply
        0
        • B berba

          When a variable in my stored procedure contains an apostrophe, it returns me an error. I've tried the function REPLACE() but no luck. waiting for your suggesions. Thanks

          T Offline
          T Offline
          thatraja
          wrote on last edited by
          #4

          You must post your query in your question. Replace single quote in sql server[^] BTW enjoy those brief explanations there

          thatraja


          **My Tip/Tricks
          My Dad had a Heart Attack on this day so don't...
          **

          B 1 Reply Last reply
          0
          • B berba

            When a variable in my stored procedure contains an apostrophe, it returns me an error. I've tried the function REPLACE() but no luck. waiting for your suggesions. Thanks

            B Offline
            B Offline
            berba
            wrote on last edited by
            #5

            CREATE PROCEDURE sp_GetEZQueryList @@sUser as nchar(500), @@sSupervisor as char(1), @@sAllowed as varchar(8000) AS --set @@sUser = REPLACE(@@sUser, '''''','''''') IF @@sSupervisor <> 'Y' SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery WHERE (EzqUserName=@@sUser) OR (EzqUserName='SYSTEM' AND Cast(EzqFlxID as varchar(10)) IN (select * FROM intlist_to_tbl(@@sAllowed))) ELSE SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery GO The SP is retrieving @@sUser from VB and its getting the value Do'Sullivan. When I ran a trace I found it is executing the SP like this exec sp_getezquerylist 'DO' + CHAR(39) + 'SULLIVAN', 'n', '100' Think + CHAR(39) + is causing the error Thanks

            B S 2 Replies Last reply
            0
            • T thatraja

              You must post your query in your question. Replace single quote in sql server[^] BTW enjoy those brief explanations there

              thatraja


              **My Tip/Tricks
              My Dad had a Heart Attack on this day so don't...
              **

              B Offline
              B Offline
              berba
              wrote on last edited by
              #6

              CREATE PROCEDURE sp_GetEZQueryList @@sUser as nchar(500), @@sSupervisor as char(1), @@sAllowed as varchar(8000) AS --set @@sUser = REPLACE(@@sUser, '''''','''''') IF @@sSupervisor <> 'Y' SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery WHERE (EzqUserName=@@sUser) OR (EzqUserName='SYSTEM' AND Cast(EzqFlxID as varchar(10)) IN (select * FROM intlist_to_tbl(@@sAllowed))) ELSE SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery GO The SP is retrieving @@sUser from VB and its getting the value Do'Sullivan. When I ran a trace I found it is executing the SP like this exec sp_getezquerylist 'DO' + CHAR(39) + 'SULLIVAN', 'n', '100' Think + CHAR(39) + is causing the error Thanks

              1 Reply Last reply
              0
              • B berba

                CREATE PROCEDURE sp_GetEZQueryList @@sUser as nchar(500), @@sSupervisor as char(1), @@sAllowed as varchar(8000) AS --set @@sUser = REPLACE(@@sUser, '''''','''''') IF @@sSupervisor <> 'Y' SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery WHERE (EzqUserName=@@sUser) OR (EzqUserName='SYSTEM' AND Cast(EzqFlxID as varchar(10)) IN (select * FROM intlist_to_tbl(@@sAllowed))) ELSE SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery GO The SP is retrieving @@sUser from VB and its getting the value Do'Sullivan. When I ran a trace I found it is executing the SP like this exec sp_getezquerylist 'DO' + CHAR(39) + 'SULLIVAN', 'n', '100' Think + CHAR(39) + is causing the error Thanks

                B Offline
                B Offline
                berba
                wrote on last edited by
                #7

                Any solutions ?? Cheers

                1 Reply Last reply
                0
                • B berba

                  CREATE PROCEDURE sp_GetEZQueryList @@sUser as nchar(500), @@sSupervisor as char(1), @@sAllowed as varchar(8000) AS --set @@sUser = REPLACE(@@sUser, '''''','''''') IF @@sSupervisor <> 'Y' SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery WHERE (EzqUserName=@@sUser) OR (EzqUserName='SYSTEM' AND Cast(EzqFlxID as varchar(10)) IN (select * FROM intlist_to_tbl(@@sAllowed))) ELSE SELECT EzqDateMod, EzqFlxID, EzqUserName, EzqName, EzqData, EzqDescrip FROM EZQuery GO The SP is retrieving @@sUser from VB and its getting the value Do'Sullivan. When I ran a trace I found it is executing the SP like this exec sp_getezquerylist 'DO' + CHAR(39) + 'SULLIVAN', 'n', '100' Think + CHAR(39) + is causing the error Thanks

                  S Offline
                  S Offline
                  S Douglas
                  wrote on last edited by
                  #8

                  Little Debugging..

                  CREATE PROCEDURE sp_GetEZQueryList
                  (
                  @sUser AS nchar(500) ,
                  @sSupervisor AS char(1) ,
                  @sAllowed AS varchar(8000)
                  )
                  AS

                  IF @sSupervisor <> 'Y'
                  SELECT
                  EzqDateMod ,
                  EzqFlxID ,
                  EzqUserName ,
                  EzqName ,
                  EzqData ,
                  EzqDescrip
                  FROM
                  EZQuery
                  WHERE
                  ( EzqUserName = @sUser )
                  OR
                  ( EzqUserName = 'SYSTEM' /*AND CAST(EzqFlxID AS varchar(10)) IN ( SELECT * FROM intlist_to_tbl WHERE(@sAllowed) ) */)

                  ELSE
                  SELECT
                  EzqDateMod ,
                  EzqFlxID ,
                  EzqUserName ,
                  EzqName ,
                  EzqData ,
                  EzqDescrip
                  FROM
                  EZQuery
                  GO

                  exec sp_getezquerylist 'DO''SULLIVAN', 'N', '100'

                  Executes fine, without the IN clase to look up The source of your issues appear to be in this function (I assume its a function based on the nomenclature) intlist_to_tbl. If intlist_to_tbl is really a function why are you sending that data to the db, and converting it instead of storing it in the db?


                  Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

                  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