title: Filename with varing date and time for restore database
body: <p>I am trying to pick up a daily .bak file which has a static name but a date and time stamp within the file name in the format 'Filename_yyyyMMdd_hhmm.bak'.</p>
  
  <p>The script I have created works if I manually enter the time to match the file but when I try and automate it, it wont work because the time can change when the file is generated (generally only by a matter on minutes.</p>
  
  <p>Would someone be able to help on how to rectify this?</p>
  
  <pre><code>    DECLARE @BackupFile varchar(1000)
  
      SELECT @BackupFile = SELECT '\NETWORKLOCATION\FILENAME_' + FORMAT(CAST(GETDATE()  AS date),'yyyyMMdd') + '_HHmm.bak')
  
      RESTORE DATABASE [Test]
      FROM DISK = @BackupFile
      WITH REPLACE
  </code></pre>
  
  <p>I'm using SQL Server.</p>