11 Replies Latest reply: Oct 14, 2012 10:33 PM by benton RSS

    how to use CASE and COUNT statements in SELECT QUERY

    950270
      Hi ALL

      I want to count the batch records using BATCH_ID with CASE statement ,for that i am using below query but its not working ,

      SELECT COUNT(*) FROM <TABLENAME> WHERE VNBATCH_ID=CASE WHEN #SDC <10 AND #PERIOD >=10 THEN
      0||#SDC||#PERIOD||#BATCH_ID
      WHEN #SDC <10 AND #PERIOD <10 THEN
      0||#SDC||0||#PERIOD||#BATCH_ID
      WHEN #SDC >=10 AND #PERIOD <10 THEN
      #SDC||0||#PERIOD||#BATCH_ID
      ELSE
      #SDC||#PERIOD||#BATCH_ID
      END

      Please any one help me regarding this,i donot know SQL much,urgent plzzz
      Thanks in Advance