MSSQL: Restore a DB to the latest file in a backup set
Something like this may do the trick. I just quickly modified something I use for a slightly different purpose.
declare @dbname varchar(80),
@lastfull datetime,
@fullback varchar(1024),
@position int,
@SQL nvarchar(max)
set @dbname = 'YourDB'
select @lastfull = MAX(backup_finish_date)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.backupset b ON d.name = b.database_name AND b.type = 'D'
WHERE d.database_id NOT IN (2, 3) and d.name=@dbname
SELECT @fullback = m.physical_device_name, @position = b.position
FROM msdb.dbo.backupmediafamily AS m INNER JOIN
msdb.dbo.backupset AS b ON m.media_set_id = b.media_set_id
and b.type='D' and b.database_name=@dbname
AND b.backup_finish_date=@lastfull
set @SQL = 'RESTORE DATABASE [' + @DBname + '] FROM DISK = N''' + @fullback + ''' WITH FILE = ' + convert(nvarchar,@position) + ', RECOVERY, NOUNLOAD, STATS = 10'
EXEC SP_EXECUTESQL @SQL
It pulls the last backup date for the database in question and fills in the path and position for you.