Create Temp Table for getting max date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anne150585
    New Member
    • Apr 2007
    • 3

    Create Temp Table for getting max date

    Hi,

    I was wandering if anyone could give me some help...
    The idea is that I want to create a stored procedure that will check a bunch of tables and give me the latest 'LastUpdated' field

    Something like:-
    Select Max(LastUpdated )
    from Table1
    = @date1
    Add Date1 to tempTable

    Repeat for each table

    And then get the max date of all dates in the temp table and return this...

    Any Help would be much appreciated
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    If you have no more than 16 tables you can get away with this:


    [PHP]Select Max(LastUpdated )
    FROM (
    select LastUpdate from Table1
    UNION
    select LastUpdate from Table2
    UNION
    select LastUpdate from Table3
    ....
    UNION
    select LastUpdate from Table16) a[/PHP]

    Good Luck.

    Comment

    Working...