(Excuse the amateur nature of the question)
I am trying to pass the servername and database name to a stored procedure which does some logging as follows
exec [dbo].[Logger]
@Server = @@servername,
@Database = db_name(db_id()),
@Task = 'Some task';
but I keep getting this error -
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near 'db_id'.
I have got this to work using declare @dbname varchar(255) = db_name(db_id());
at the top and then using that. But it seems like an unnecessary variable.
Thanks