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. Please modify the Stored procedure (Error:-incorrect syntax near '+')

Please modify the Stored procedure (Error:-incorrect syntax near '+')

Scheduled Pinned Locked Moved Database
databasehelpsharepointcareer
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.
  • V Offline
    V Offline
    vinu 1111
    wrote on last edited by
    #1

    hi.. the below is my SP.. i want to pass the parameter @name to the open query but it is showing the error incorrect syntax near '+' ALTER PROCEDURE [dbo].[cub] @name nvarchar(50) AS BEGIN SET NOCOUNT ON; select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,'select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1, [Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+ @name +' ') END if i pass the value directly.. like this.. where [Employee].[Empname].&vasu ') it will execute fine.. but through the parameter name it will show error.. help me..

    S W S 3 Replies Last reply
    0
    • V vinu 1111

      hi.. the below is my SP.. i want to pass the parameter @name to the open query but it is showing the error incorrect syntax near '+' ALTER PROCEDURE [dbo].[cub] @name nvarchar(50) AS BEGIN SET NOCOUNT ON; select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,'select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1, [Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+ @name +' ') END if i pass the value directly.. like this.. where [Employee].[Empname].&vasu ') it will execute fine.. but through the parameter name it will show error.. help me..

      S Offline
      S Offline
      s_magus
      wrote on last edited by
      #2

      The problem is 'OPENQUERY does not accept variables for its arguments.' The following link has a potential work around if you must use OPENQUERY: Passing-variables-into-an-OPENQUERY-argument.

      1 Reply Last reply
      0
      • V vinu 1111

        hi.. the below is my SP.. i want to pass the parameter @name to the open query but it is showing the error incorrect syntax near '+' ALTER PROCEDURE [dbo].[cub] @name nvarchar(50) AS BEGIN SET NOCOUNT ON; select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,'select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1, [Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+ @name +' ') END if i pass the value directly.. like this.. where [Employee].[Empname].&vasu ') it will execute fine.. but through the parameter name it will show error.. help me..

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        You have several options for this and they all have their downsides. Here's few. One way is to create the statement and concatenate the parameter values to a string variable. After that you can execute the contents of the variable using EXEC[^]. This may lead to problems when dates, numbers etc are used in the parameters. Another option is to create a permanent or temporary table and insert the parameter values to this table and join the openquery to this table. Of course you can use other conditions also (exists, 'column returned by openquery' < 'value in temp table' etc etc). Now you can build a data-type safe solution but you may encounter performance problems.

        The need to optimize rises from a bad design.My articles[^]

        1 Reply Last reply
        0
        • V vinu 1111

          hi.. the below is my SP.. i want to pass the parameter @name to the open query but it is showing the error incorrect syntax near '+' ALTER PROCEDURE [dbo].[cub] @name nvarchar(50) AS BEGIN SET NOCOUNT ON; select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,'select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1, [Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+ @name +' ') END if i pass the value directly.. like this.. where [Employee].[Empname].&vasu ') it will execute fine.. but through the parameter name it will show error.. help me..

          S Offline
          S Offline
          SamRST
          wrote on last edited by
          #4

          hi, when we pass the parameter , not need of the quotes. for eg: without param select * from employee where ename='sss'; with param Declare en as varchar(5); set en='wowow'; select * from employee where ename=@en; Good luck.

          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