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. sqlserver apostrophe problem.

sqlserver apostrophe problem.

Scheduled Pinned Locked Moved Database
databasehelpsharepoint
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.
  • G Offline
    G Offline
    gerrybrennan
    wrote on last edited by
    #1

    Hi I have a stored procedure schemacreate.sql and below is a snippet. I am having problems with creating the below procedure. More specifically and TransType = "SI" Can any one help me with this. Thank you in advance. G

    SET ANSI_NULLS ON

    SET QUOTED_IDENTIFIER OFF

    IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[TransCheckifCurrentExists]') AND type in (N'P', N'PC'))
    BEGIN
    EXEC dbo.sp_executesql @statement = N'
    CREATE PROCEDURE [dbo].[TransCheckifCurrentExists]

    as
    declare @SQLstr nvarchar(1000)
    declare @value int;

    set @SQLstr = ''select @value=count(*) from Trans where TransState = 1 and TransType = "SI" ''

    exec sp_executesql @SQLstr, N''@value int out'', @value out
    return

    '
    END

    A N N B 4 Replies Last reply
    0
    • G gerrybrennan

      Hi I have a stored procedure schemacreate.sql and below is a snippet. I am having problems with creating the below procedure. More specifically and TransType = "SI" Can any one help me with this. Thank you in advance. G

      SET ANSI_NULLS ON

      SET QUOTED_IDENTIFIER OFF

      IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[TransCheckifCurrentExists]') AND type in (N'P', N'PC'))
      BEGIN
      EXEC dbo.sp_executesql @statement = N'
      CREATE PROCEDURE [dbo].[TransCheckifCurrentExists]

      as
      declare @SQLstr nvarchar(1000)
      declare @value int;

      set @SQLstr = ''select @value=count(*) from Trans where TransState = 1 and TransType = "SI" ''

      exec sp_executesql @SQLstr, N''@value int out'', @value out
      return

      '
      END

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Double quotes are not valid to enclose literals, you need single quotes. I would suugest before executing your sql string you print it (at least for debug) as it soon shows any syntax errors.

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      G 1 Reply Last reply
      0
      • A Ashfield

        Double quotes are not valid to enclose literals, you need single quotes. I would suugest before executing your sql string you print it (at least for debug) as it soon shows any syntax errors.

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        G Offline
        G Offline
        gerrybrennan
        wrote on last edited by
        #3

        Hi Bob, Thank you for your help. When I use single quotes i get an error Line 16: Incorrect syntax near 'SI'. G

        1 Reply Last reply
        0
        • G gerrybrennan

          Hi I have a stored procedure schemacreate.sql and below is a snippet. I am having problems with creating the below procedure. More specifically and TransType = "SI" Can any one help me with this. Thank you in advance. G

          SET ANSI_NULLS ON

          SET QUOTED_IDENTIFIER OFF

          IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[TransCheckifCurrentExists]') AND type in (N'P', N'PC'))
          BEGIN
          EXEC dbo.sp_executesql @statement = N'
          CREATE PROCEDURE [dbo].[TransCheckifCurrentExists]

          as
          declare @SQLstr nvarchar(1000)
          declare @value int;

          set @SQLstr = ''select @value=count(*) from Trans where TransState = 1 and TransType = "SI" ''

          exec sp_executesql @SQLstr, N''@value int out'', @value out
          return

          '
          END

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

          Try and TransType =

          ''SI''

          :)

          Niladri Biswas

          1 Reply Last reply
          0
          • G gerrybrennan

            Hi I have a stored procedure schemacreate.sql and below is a snippet. I am having problems with creating the below procedure. More specifically and TransType = "SI" Can any one help me with this. Thank you in advance. G

            SET ANSI_NULLS ON

            SET QUOTED_IDENTIFIER OFF

            IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[TransCheckifCurrentExists]') AND type in (N'P', N'PC'))
            BEGIN
            EXEC dbo.sp_executesql @statement = N'
            CREATE PROCEDURE [dbo].[TransCheckifCurrentExists]

            as
            declare @SQLstr nvarchar(1000)
            declare @value int;

            set @SQLstr = ''select @value=count(*) from Trans where TransState = 1 and TransType = "SI" ''

            exec sp_executesql @SQLstr, N''@value int out'', @value out
            return

            '
            END

            N Offline
            N Offline
            Nilesh Kuvar
            wrote on last edited by
            #5

            Hello, Generally here, apostrophe is considered as escape sequence character You may execute as TransType = ''SI'' This may solve you problem :thumbsup:

            1 Reply Last reply
            0
            • G gerrybrennan

              Hi I have a stored procedure schemacreate.sql and below is a snippet. I am having problems with creating the below procedure. More specifically and TransType = "SI" Can any one help me with this. Thank you in advance. G

              SET ANSI_NULLS ON

              SET QUOTED_IDENTIFIER OFF

              IF NOT EXISTS (select * from sysobjects where id = object_id(N'[dbo].[TransCheckifCurrentExists]') AND type in (N'P', N'PC'))
              BEGIN
              EXEC dbo.sp_executesql @statement = N'
              CREATE PROCEDURE [dbo].[TransCheckifCurrentExists]

              as
              declare @SQLstr nvarchar(1000)
              declare @value int;

              set @SQLstr = ''select @value=count(*) from Trans where TransState = 1 and TransType = "SI" ''

              exec sp_executesql @SQLstr, N''@value int out'', @value out
              return

              '
              END

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

              Use CHAR(39) for single apostrophe.


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

              G 1 Reply Last reply
              0
              • B Blue_Boy

                Use CHAR(39) for single apostrophe.


                I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

                G Offline
                G Offline
                gerrybrennan
                wrote on last edited by
                #7

                Eventually got it ''''SI'''' Solved the problem. Many Thanks G.

                B 1 Reply Last reply
                0
                • G gerrybrennan

                  Eventually got it ''''SI'''' Solved the problem. Many Thanks G.

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #8

                  Good,but when you have complex query and in which you use multiple times single apostrophe then you can become confused by writing much '''' in query. Regards.


                  I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

                  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