Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How can I use MAX() function in another DataBAse? Expand / Collapse
Posted Saturday, November 30, 2013 11:17 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, September 24, 2015 2:56 AM
Points: 42, Visits: 125
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'.
Post #1518683
Posted Sunday, December 1, 2013 3:09 AM



Group: General Forum Members
Last Login: Today @ 11:15 AM
Points: 43,490, Visits: 40,634
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
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

Post #1518689
Posted Sunday, December 1, 2013 3:55 PM



Group: General Forum Members
Last Login: Today @ 8:50 AM
Points: 38,987, Visits: 36,074
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Favorite Quotes:
"Has anyone ever told you that a query you have written runs too fast?" - Dwain Camps - 6 Mar 2014

Helpful Links:
How to post code problems
How to post performance problems
Post #1518717
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse