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:
…and you get the following error stating “The index 2 is out of range”:
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: