3 Replies Latest reply on Dec 26, 2013 12:45 PM by kettan

    SQL Case Statement using like

    Michael Holloway



      I'm trying to replicate a SQL Server query in Tableau using a case statement and like.  I have a comment column and several comments can be placed in the same column.  New comments are appended to existing comments.  Comments are delimited by pipes, e.g. '|'


      I want to count the pipes to know how many comments are in said column.


      SQL would accomplish as:


      SELECT      CMNT_X,

                            CASE WHEN cmnt_X LIKE '%|%|%|%|%' THEN 5 WHEN cmnt_X LIKE '%|%|%|%' THEN 4 WHEN cmnt_X LIKE '%|%|%' THEN 3 WHEN cmnt_X LIKE '%|%' THEN 2 ELSE 1 END

                             AS PIPE_CNT

      FROM         TABLE.A


      Any Ideas on how to accomplish? 


      Thanks!  Michael