Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Too much egg nog - Query Help - lol 1

Status
Not open for further replies.

JayKusch

MIS
Oct 30, 2001
3,199
US
I am trying to update a record set with the last restore date that is captured with a TOP clause in the code.

Here is the code (that does not work):

Code:
UPDATE	MyTable
  SET MyDate = 
       ( SELECT TOP 1 RESTORE_DATE
         FROM MSDB.dbo.RESTOREHISTORY WITH (nolock)
	 JOIN	MyTable
	 ON	DESTINATION_DATABASE_NAME = DatabaseName )
FROM       MyTable	AS mt
INNER JOIN MSDB.dbo.RESTOREHISTORY                
ON	   DESTINATION_DATABASE_NAME = mt.DatabaseName

Thanks!

Thanks

J. Kusch
 
Try this:

Code:
UPDATE MyTable
SET    MyDate = MaxRestoreDates.Restore_Date
FROM   MyTable AS mt
       INNER JOIN (
          SELECT Max(restore_date) As Restore_Date, 
                 destination_database_name
          FROM   MSDB.dbo.RESTOREHISTORY WITH (nolock)
          Group By destination_database_name
          ) As MaxRestoreDates
              ON MaxRestoreDates.DESTINATION_DATABASE_NAME = mt.DatabaseName


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top