I have bottom T-SQL Script:
USE [master]
RESTORE DATABASE [WH_BEE] FROM
DISK = N'F:NHWH_BEE_20240819_1.bak',
DISK = N'F:NHWH_BEE_20240819_2.bak',
DISK = N'F:NHWH_BEE_20240819_3.bak',
DISK = N'F:NHWH_BEE_20240819_4.bak',
DISK = N'F:NHWH_BEE_20240819_5.bak',
DISK = N'F:NHWH_BEE_20240819_6.bak' WITH FILE = 1,
MOVE N'WH_Data1' TO N'F:dataWH_BEE.MDF',
MOVE N'WH_Data2' TO N'F:dataWH_BEE_1.NDF',
MOVE N'WH_Log' TO N'G:logWH_BEE.LDF', NOUNLOAD, STATS = 5
What I am trying to do is instead of indicating individual date like ‘20240819’, how do I modify these portions (using a wildcard) so that it is more like:
DISK = N'F:NMWH_BEE_' + * + '_1.bak'
DISK = N'F:NMWH_BEE_' + * + '_2.bak'
DISK = N'F:NMWH_BEE_' + * + '_3.bak'
DISK = N'F:NMWH_BEE_' + * + '_4.bak'
DISK = N'F:NMWH_BEE_' + * + '_5.bak'
DISK = N'F:NMWH_BEE_' + * + '_6.bak'
Also, if possibly having more than just 6 files, can I make this T-SQL more dynamic (instead of having strictly 6, just in case it can go up to 7..)?