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. SQL SP exception: "Incorrect syntax near '-'"

SQL SP exception: "Incorrect syntax near '-'"

Scheduled Pinned Locked Moved Database
databasequestionsharepointannouncement
2 Posts 2 Posters 1 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.
  • C Offline
    C Offline
    cdietschrun
    wrote on last edited by
    #1

    I am getting an exception thrown from my web app's call to a SQL SP. The expecption says "incorrect syntax near '-'". The dash I have narrowed down to an argument passed to the stored procedure contains dashes, such as 992-123-123. The SP works fine if the argument passed is 992123123. What is the best way of fixing this? In all likelyhood it is more important to keep the dashes in the entries in the columns. I think it is just my SP syntax, so here it is: @PACKAGE is the value that is giving issues, which is 999-999-999 style. CODE

    CREATE PROCEDURE dbo.sp_UpdateItemColumn
    (
    @PACKAGE nvarchar(255),
    @COLUMN nvarchar(30),
    @VALUE nvarchar(100),
    @LASTCHANGEBY nvarchar(100)
    )
    AS

    declare @sql nvarchar(1024)
    set @sql=''

    set @sql=@sql+'update tbl_swbom_checklist_items set '+@COLUMN+'='''+@VALUE+''' where package='''+@PACKAGE+''' '

    --print @sql

    exec sp_executesql @sql
    GO

    T 1 Reply Last reply
    0
    • C cdietschrun

      I am getting an exception thrown from my web app's call to a SQL SP. The expecption says "incorrect syntax near '-'". The dash I have narrowed down to an argument passed to the stored procedure contains dashes, such as 992-123-123. The SP works fine if the argument passed is 992123123. What is the best way of fixing this? In all likelyhood it is more important to keep the dashes in the entries in the columns. I think it is just my SP syntax, so here it is: @PACKAGE is the value that is giving issues, which is 999-999-999 style. CODE

      CREATE PROCEDURE dbo.sp_UpdateItemColumn
      (
      @PACKAGE nvarchar(255),
      @COLUMN nvarchar(30),
      @VALUE nvarchar(100),
      @LASTCHANGEBY nvarchar(100)
      )
      AS

      declare @sql nvarchar(1024)
      set @sql=''

      set @sql=@sql+'update tbl_swbom_checklist_items set '+@COLUMN+'='''+@VALUE+''' where package='''+@PACKAGE+''' '

      --print @sql

      exec sp_executesql @sql
      GO

      T Offline
      T Offline
      Thats Aragon
      wrote on last edited by
      #2

      hi there, please try to do below query. It is working perfect with the '-' value.

      declare @sql nvarchar(1024)
      set @sql=''
      set @sql=@sql+'update tbl_swbom_checklist_items set ' + @COLUMN + '=' + '''' +@VALUE + ''' where @PACKAGE='''+ @PACKAGE +''''
      exec (@sql)

      Regards :)

      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