I had a typo of missing an @ from a use of a variable. Normally SQL will compain about an undeclared variable. However in the case where it is used a sproc parameter sql server doesn't complain. It simply infers some singe quotes and moves on.
Can anyone explain why example C does not error?
--Ex A. Error
SELECT id
--Ex B. Error
CREATE FUNCTION dbo.fnTest (
@id NVARCHAR(4)
) RETURNS NVARCHAR(4) AS BEGIN
RETURN @id
END
GO
DECLARE @id NVARCHAR(4)
SET @id= 'bob'
SELECT dbo.fnTest(@id) --missing my @, this should be @id
--SELECT dbo.fnTest(id) --missing my @, this should be @id
GO
DROP FUNCTION fnTest
--Ex C. No Error
CREATE PROC spTest (
@id NVARCHAR(4)
) AS
SELECT @id
GO
DECLARE @id NVARCHAR(4)
SET @id= 'bob'
EXEC spTest id --missing my @, this should be @id
GO
DROP PROC spTest