I have a dynamic SQL query
DECLARE @ItemAreaCode NVARCHAR(MAX) = 'A062',
@SQLStringDropTable NVARCHAR(MAX);
SET @SQLStringDropTable= 'DROP TABLE' + ' ' +
'[@ItemAreaCode].[ChangedRMAllocation]'
PRINT @ItemAreaCode
EXEC sp_executesql @SQLStringDropTable , N'@ItemAreaCode NVARCHAR(MAX)', @ItemAreaCode;
But when I execute this, I get this error:
Msg 3701, Level 11, State 5, Line 1
Cannot drop the table '@ItemAreaCode.ChangedRMAllocation', because it does not exist or you do not have permission.
And the printed query is..
DROP TABLE [@ItemAreaCode].[ChangedRMAllocation];
What I need is:
DROP TABLE [A062].[ChangedRMAllocation];