Search code examples
sql-servert-sqlred-gate-sql-prompt

Why do I keep getting Incorrect usage of const UDF in SSMS?


I keep getting warnings in SSMS (using v17.7) and RedGate SQL Prompt:

Incorrect usage of const UDF

It underlines SYSUTCDATETIME()

The following underlines SYSUTCDATETIME() in both places

   SELECT 2
     FROM (VALUES (CAST('2020-06-26' AS DATETIME2(7)))) AS s (SampleAt)
    WHERE s.SampleAt BETWEEN SYSUTCDATETIME() AND DATEADD(DAY, 100, SYSUTCDATETIME())

The following doesn't underline it at all:

    SELECT 2
     WHERE CAST('2020-06-26' AS DATETIME2(7)) BETWEEN SYSUTCDATETIME() AND DATEADD(DAY, 100, SYSUTCDATETIME())

Also doesn't underline it at all:

DECLARE @now AS DATETIME2 = SYSUTCDATETIME()

   SELECT 2
     FROM (VALUES (CAST('2020-06-26' AS DATETIME2(7)))) AS s (SampleAt)
    WHERE s.SampleAt BETWEEN @now AND DATEADD(DAY, 100, @now)


Solution

  • I spoke with the developers. This is a bug in the tool. Thanks for identifying it. They're actively working to get a fix in place and it should be published soon.