parametrize linked server name

  • Hi,

    Is it possible to parametrize a remote procedure through a linked server or a query through a linked server?

    I am trying to parametrize the name of the linked server in something like this:

    select count(*) from REMOTESERVER.database.dbo.table

    How can I do that?

    Thanks,

    Janos

  • Janos Horanszky (10/23/2008)


    Hi,

    Is it possible to parametrize a remote procedure through a linked server or a query through a linked server?

    I am trying to parametrize the name of the linked server in something like this:

    select count(*) from REMOTESERVER.database.dbo.table

    How can I do that?

    Thanks,

    Janos

    yes you can

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • For example:

    declare @remoteserver nvarchar(50)

    declare @cmd nvarchar(255)

    declare @rc int

    declare @nCount int

    select @remoteserver = 'SYED_ALI,1533'

    set @cmd = 'select @nCount = count(*) from ['+@remoteserver+'].chartwellgame.dbo.CountPlaceholder (nolock)'

    exec sp_executesql @cmd, N'@nCount int out', @nCount out

    select @nCount as cnt

    gives me:

    Msg 4122, Level 16, State 1, Line 1

    Remote table-valued function calls are not allowed.

    cnt

    -----------

    NULL

    Why is that?

  • Oh, okay, it does not support the (nolock) hint.

    If I take it out, it works!

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

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