Query help required

  • declare @report_instance nvarchar(50)

    select @report_instance =

    case

    when @@servername like '%HQ04%' then 'HQ_REPORT'

    when @@servername like '%INDBA02%' then 'IN_REPORT'

    end

    select top 1 * from (select @report_instance).master.dbo.sysobjects

    Msg 102, Level 15, State 1, Line 13

    Incorrect syntax near '.'.

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • You can't parameterise a schema as such.You need to create a dynamic sql string and execute that.

  • declare @report_instance nvarchar(50)

    select @report_instance =

    case

    when @@servername like '%HQ04%' then 'HQ_REPORT'

    when @@servername like '%INDBA02%' then 'IN_REPORT'

    end

    select @report_instance

    Declaring a variable doesn't make an object.

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

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