Using a parameter as a server name in an execute SQL task

  • Hi All,

    I was hoping someone could help me out with an issue which has been frustrating me this afternoon. All i am trying to do is pass a server name (stored as a project parameter) into an execute SQL task as parameter. I am fine with the parameter mapping process and using question mark replacements however it doesn't seem to like being used in a linked server query.

    The code in question looks like the following

    MERGE MyTargetTable AS target

    USING (SELECT ID from ?.MyDatabase.dbo.MyTable) AS source (ID)

    ON (source.ID = Target.ID)

    This fails with "incorrect syntax near ." so it appears on the face of it that i am unable to pass a parameter in as a server name.

    Any ideas/workarounds?

    Thanks in advance,

    John

  • Animal Magic (9/14/2015)


    Hi All,

    I was hoping someone could help me out with an issue which has been frustrating me this afternoon. All i am trying to do is pass a server name (stored as a project parameter) into an execute SQL task as parameter. I am fine with the parameter mapping process and using question mark replacements however it doesn't seem to like being used in a linked server query.

    The code in question looks like the following

    MERGE MyTargetTable AS target

    USING (SELECT ID from ?.MyDatabase.dbo.MyTable) AS source (ID)

    ON (source.ID = Target.ID)

    This fails with "incorrect syntax near ." so it appears on the face of it that i am unable to pass a parameter in as a server name.

    Any ideas/workarounds?

    Thanks in advance,

    John

    Dynamic SQL

    😎

  • I thought that may be the case. Cheers

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

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