sqlguy-736318 (11/3/2011)
I'm in the process of creating a database restore script for my staging server.Whenever I restore a database on my staging server I always restore a bak file with the latest timestamp from a specific filesystem directory. Therefore, I'd like to automate this process in my restore script.
Can you show me the T/SQL I should use to get the filename of the bak file with the latest timestamp from a specific filesystem directory?
What is the format of the filenames that you have? I ask because if they look like the following (has an ISO-style date and time embedded in the name), there is a VERY simple way to do this without using xp_CmdShell, SQLCLR, VBScripts, Powershell, or any other non-built-in method...
dbname_backup_200810292330.bak
--Jeff Moden
Change is inevitable... Change for the better is not.