Missing Linked Server

  • Hi,

    I have an issue with one of my production servers. I have a few production servers, and they all have the same objects. I do not want to create custom objects for each one, rather keep them all standard.

    However, due to environment issues, I have one which does not have any linked servers.

    I have a proc which queries either locally or across the linked server depending on the value of a switch. I want to install this proc on the server with no linked servers but it obviously fails.

    I can guarantee the proc will never be called with the switch 'on' on that particular server. We still want to install this proc and call it with a switch of 0.

    Please can somebody come up with something really clever.

    The proc goes something like this:

    CREATE PROC WhatEver @Switch int

    AS

    IF @Switch = 1

    BEGIN

    SELECT * FROM LinkedServer.Db.dbo.MyTable

    END

    ELSE BEGIN

    SELECT * FROM dbo.MyTable

    END

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Hi Sean Pearce,

    Please check if the below code works.

    It did not show any error for me.

    CREATE PROC WhatEver @Switch int

    AS

    Begin

    Declare @SQL as Varchar(Max)

    IF @Switch = 1

    BEGIN

    SET @SQL = 'SELECT * FROM LinkedServer.Db.dbo.MyTable'

    END

    ELSE BEGIN

    SET @SQL = 'SELECT * FROM dbo.MyTable'

    END

    EXEC @SQL

    End

  • Thanks for your reply. I am going to give it a bash now and let you know the results.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Thank you. That works like the bomb.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

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

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