Hi anonymous user,
Thank you so much for posting here.
You could try with dynamic SQL statement as below:
BEGIN
DECLARE @SQL NVARCHAR(MAX)
DECLARE @Id INT = 6;
DECLARE @Val Varchar(10) ='UPDATE NOW';
SET @SQL= 'DELETE TESTTABLE WHERE id ='+ CONVERT(VARCHAR(10),@Id)+';'
EXECUTE sp_executesql @SQL
set @ID = 5;
SET @SQL= 'UPDATE TESTTABLE set NAME ='''+@Val+''' WHERE id = '+CONVERT(VARCHAR(10),@Id)+';'
EXECUTE sp_executesql @SQL
END
Then you could get your expected value instead of variable.
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues November--What can I do if my transaction log is full?
Hot issues November--How to convert Profiler trace into a SQL Server table