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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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