Yes, and no
You can declare the variable dynamically, and exec
the command, but its scope will be within that exec
statement, so it will vanish afterwards.
You can do
declare @t nvarchar(100) = 'declare @v int; select @v = 1; select @v+1'
exec (@t)
Or you can pass variables to commands with sp_executesql
.