I am building some scripts and found an annoyance to be that I can't provide expressions as arguments to EXEC.
Here is an example I have run into. I want to setup various items using a consistent format that includes the database name. I can't simply concatenate the strings when passing an argument
EXEC msdb.dbo.sp_help_schedule
@schedule_name = 'FullBackup_'+@DatabaseName,
...
instead I have to declare a variable just for the final string and pass that...
DECLARE @ScheduleName varchar(100)
SET @ScheduleName = 'FullBackup_'+@DatabaseName
EXEC msdb.dbo.sp_help_schedule
@schedule_name = @ScheduleName,
...
I have built up a command string dynamically when necessary which could achieve this but would rather not to do that every time. Is this a limitation in t-sql or is there a way around it?
@schedule_name = @ScheduleName,
? – Aaron Bertrand♦ 22 hours ago