TSQL dilemma

  • Code snippet:

    use testdb2

    go

    DECLARE @filevalue varchar(50), @VarFileName varchar(50);

    exec dbo.Get_Current_filename @filevalue OUTPUT

    select @VarFileName = selected_file from dbo.FinalResult;

    select @VarFileName...result is valid

    use master

    go

    select @VarFileName....result is NULL of course.

    How can I extract a value from a table using a declared variable and reference that same variable from a different database? The master database is part of the testdb2 environment.

    Please help. It can't be that difficult.

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

  • Remove the 'go' after 'use master' and try again.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Or:

    use master

    go

    DECLARE @filevalue varchar(50), @VarFileName varchar(50);

    exec testdb2.dbo.Get_Current_filename @filevalue OUTPUT

    select @VarFileName = selected_file from testdb2.dbo.FinalResult;

    select @VarFileName...result is valid

    _____________
    Code for TallyGenerator

  • Thank you. I believe this will address my dilemma.

    When the snows fall and the white winds blow,The lone wolf dies but the pack survives.

    Once you've accepted your flaws, no one can use them against you.

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

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