The following SQL statement works fine:
DECLARE @database VARCHAR(30) = 'DEMO';
BACKUP LOG @database
TO DISK = N'C:\zbackups\DEMO.trn'
WITH NOFORMAT, NOINIT,
NAME = N'MyDatabase Log Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10;
DBCC SHRINKFILE ('DEMO_log', 500);
This however does not:
DECLARE @database VARCHAR(30) = 'DEMO';
BACKUP LOG @database
TO DISK = 'C:\zbackups\' + @database + '.trn'
WITH NOFORMAT, NOINIT,
NAME = 'MyDatabase Log Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10;
DBCC SHRINKFILE (@database + '_log', 500);
Both the TO DISK directive and the DBCC SHRINKFILE parameters throw an error when I attempt to concatenate.
How do I use a variable in these location? Would also like to append some datetime parameters to the file path but haven't started researching that yet.