So why doesn’t this work?
<!-- language: lang-sql -->
DECLARE @tn NVARCHAR
SET @tn = 'MyTable'
SELECT OBJECT_ID(@tn)
When this does:
<!-- language: lang-sql -->
SELECT OBJECT_ID('MyTable')
I need to pass a variable into this function.
It does.
In your example you declare a variable of length 1 (since you omit the length).
OBJECT_ID(N'M')finds nothing and returns NULL.