Amount using CASE when using Len (column_name)

I am writing a query that counts the number of records for which the number of characters is less than 11.

SELECT sum(CASE when LEN(Summary) > 11 then 0 else 1) AS [SummaryErrorCnt],
       sum(CASE when LEN(ResolutionNotes) >11 then 0 else 1) AS [ResolutionNotesErrorCnt]
FROM dbo.TicketLog

But I get an error

Msg 156, Level 15, State 1, Line 2 Incorrect syntax next to the keyword 'FROM'.

I close brackets correctly.

What am I doing wrong?

+4
source share
1 answer

You are missing a keyword ENDfor expressions CASE, for example:

CASE when LEN(Summary) > 11 then 0 else 1 END
                                          ^^^-- must close CASE with END
+3
source

All Articles