Here is a starting point...I use this to restore databases to my DR server...
Good Luck
ALTER PROCEDURE [dbo].[P_RestoreDatabase_DBName]
AS
SET NOCOUNT ON
DECLARE @DBName VARCHAR( 64 ) = 'DBName'
DECLARE @DirName VARCHAR( 256 )
DECLARE @FileName VARCHAR( 256 ),
@FileDate DATETIME,
@MaxFileDate DATETIME,
@DBRestoreSize BIGINT,
@DBRestoreLSN NUMERIC( 25, 0 )
DECLARE @SQL VARCHAR( 5000 )
SELECT @DirName = 'L:\' +...