[Bug-2887] Named Query throws exception on commented out UDF

So here’s an interesting one. This one had me scratching my head for a while…
Here’s a simple Named Query with a UDF that returns a DateTime:

SELECT :dateValue AS TestDate
	,FORMAT(dbo.udf_WeekEnding(:dateValue), 'yyyy-MM-dd') AS WeekEnding

This executes without any issue, but comment out the second line:
image

…and you get the following error stating “The index 2 is out of range”:
image

As you may guess, this becomes a real problem when you’re trying to debug errors by commenting out certain lines and that’s actually what caused the exception.

This ONLY happens when commenting out a UDF, but it must also reference a passed Parameter. Get rid of the passed parameter and there are no issues:
image

Yep, this is a known issue on our backlog. Our parsing for parameter substitution is very simple, and doesn’t know about commented lines.