How to pass parameters to other stored procedure at linked sever?

Viewed 35

I need some guidance on how to pass parameters to other stored procedure at linked server.

Below is an example of my stored procedure.

ALTER PROCEDURE [dbo].[udp_CountAllProjectOutputTracking] 
    @stationTypeId AS varchar(100) = NULL,
    @type AS varchar(100) = NULL,
    @project AS varchar(100) = NULL
AS
BEGIN
    IF @project = 'Dell'
    BEGIN
        EXEC ('[DATABASE].dbo.[STORED_PROCEDURE]', @stationTypeId, @type) AT [LINKED_SERVER]
    END 
    ELSE IF @project = 'Asus'
    BEGIN
        EXEC ('[DATABASE].dbo.[STORED_PROCEDURE]', @stationTypeId, @type) AT [LINKED_SERVER]
    END 
END

I'm not able to retrieve the data of parameters in linked server stored procedure. But below statement works if without sending parameters.

EXEC ('[DATABASE].dbo.[STORED_PROCEDURE]') AT [LINKED_SERVER]

Thank you in advance =)

1 Answers

You must specify remote procedure parameter placeholders along with passing param values

   ..
   EXEC ('[DATABASE].dbo.[STORED_PROCEDURE] ?,?', @stationTypeId, @type) AT [LINKED_SERVER]
   ..
Related