Skip to content
Advertisement

SQL Query – Incorrect syntax near the keyword ‘LIKE’

The following query is giving an error at ‘CASE WHEN NOT LIKE’ (Msg 156, Level 15, State 1, Line 14 Incorrect syntax near the keyword ‘LIKE’)

SELECT     
 TimeStamp, 
 TimeStampNS, 
 ISNULL(TagName, 'NoTag') AS TagName, 
 Message, 
 ConditionName, 
 ISNULL(TagName, 'NoTag') + '.' + ConditionName AS Source, 
 CENTUMMsgId, 
 StationName,  
 ISNULL(AlarmLevel,5) AS AlarmLevel,
 ActiveTime, 
 ActorID, 
 ISNULL(AlarmOff,0) AS AlarmOff,
 CASE WHEN  NOT LIKE '% ACK%' AND CENTUMMsgId IN (4353, 4355, 4609) THEN 1 ELSE 0 END AS RaiseAll, 
    CASE WHEN  LIKE '% ACK%' THEN 1 ELSE 0 END AS Acknowledge, 
    CASE WHEN CENTUMMsgId IN (4354, 4356, 4358, 4614) AND Message NOT LIKE '% ACK%' THEN 1 ELSE 0 END AS Normal, 
 PlantHierarchy, 
 'EXAOPC' AS SourceType
FROM QHistorianData.dbo.vEXAOPCCSProcessAlarm

Do you guys know what’s going on… I think I have eveything correct there.

Thank you in advance for any help.

Advertisement

Answer

I think you missed the attribute name here:

CASE WHEN <ATTRIBUTE-NAME> NOT LIKE '% ACK%' AND CENTUMMsgId IN (4353, 4355, 4609) THEN 1   ELSE 0 END AS RaiseAll, 
CASE WHEN  <ATTRIBUTE-NAME> LIKE '% ACK%' THEN 1 ELSE 0 END AS Acknowledge, 
CASE WHEN CENTUMMsgId ...
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement