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

  • 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..

  • To do this you will have to use dynamic sql, ie

    DECLARE @sql varchar(500)

    SET @sql = 'select * from OPENQUERY(XHMNDGHFYUHFGHJFFRJF,''select {[Employee].[Dept].[Dept]*[Employee].[Empno].[Empno]} on 1,[Measures].[Salary] on 0 from [Employee] where [Employee].[Empname].&'+@name+''')'

    EXEC (@sql)

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Got it ... thanks for reply...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply