How can I use MAX() function in another DataBAse?

  • Hello

    I want to use max() function and I want to read the input of this function from another database(its name is exhibitor). like below :

    select @LastDate=MAX([exhibitor.dbo.Maintable.LastUpdate])

    but I have error below

    Msg 207, Level 16, State 1, Procedure Exec_List, Line 131

    Invalid column name 'exhibitor.dbo.Maintable.LastUpdate'.

  • Because you referenced a column without a FROM clause.

    select @LastDate=MAX([LastUpdate]) FROM exhibitor.dbo.Maintable.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I'd also like to recommend that you avoid 3 part naming in code. Create a synonym for the table in the other database and then stick to 2 part naming. That way, if you even move or rename the database or the table, you won't have to find all of the places it was used in code. All you'll need to do is change the synonym.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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