• Karthik Rajashekaran
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
How can I have case condition in where clause 

I was trying to run below it says malformed 
 
Select columns 
 FROM table
  WHERE
  1 = CASE
        WHEN 'STD' = 'FULL' THEN 1
        WHEN 'STD' = 'STD'
              AND ((lastmodifieddate >= 2020-05-13T00:00:00.000Z AND lastmodifieddate <= 2020-05-13T23:59:59.000Z) 
                    OR (CreatedDate >= 2020-05-13T00:00:00.000Z AND CreatedDate <= 2020-05-13T23:59:59.000Z) 
                 ) THEN 1
        WHEN 'STD' = 'CSTM'
                AND ((lastmodifieddate >= 1970-01-01 00:00:00T00:00:00.000Z AND lastmodifieddate <= 1970-01-01 23:59:59T23:59:59.000Z)
                      OR (CreatedDate >= 1970-01-01T00:00:00.000Z AND CreatedDate <= 1970-01-01T23:59:59.000Z)
                    ) THEN 1
        ELSE 0
  END

 
How can I have case condition in where clause 

I was trying to run below it says malformed 
 
Select columns 
 FROM table
  WHERE
  1 = CASE
        WHEN 'STD' = 'FULL' THEN 1
        WHEN 'STD' = 'STD'
              AND ((lastmodifieddate >= 2020-05-13T00:00:00.000Z AND lastmodifieddate <= 2020-05-13T23:59:59.000Z) 
                    OR (CreatedDate >= 2020-05-13T00:00:00.000Z AND CreatedDate <= 2020-05-13T23:59:59.000Z) 
                 ) THEN 1
        WHEN 'STD' = 'CSTM'
                AND ((lastmodifieddate >= 1970-01-01 00:00:00T00:00:00.000Z AND lastmodifieddate <= 1970-01-01 23:59:59T23:59:59.000Z)
                      OR (CreatedDate >= 1970-01-01T00:00:00.000Z AND CreatedDate <= 1970-01-01T23:59:59.000Z)
                    ) THEN 1
        ELSE 0
  END