This discussion is archived
11 Replies Latest reply: Oct 14, 2012 8:33 PM by benton RSS

how to use CASE and COUNT statements in SELECT QUERY

950270 Newbie
Currently Being Moderated
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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points