Connecting Tech Pros Worldwide Help | Site Map

Selecting seperate fields from file - each based on different criteria

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: Oct 16 '09
We have a file with grade fields - each with a 'status' field which we would like to use as criteria for adding the the grade fields togather.
(ie. if status field for grade1 is 'A', add to sum, else bypass)

Thanks for your help
Rick
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 783
#2: Oct 19 '09

re: Selecting seperate fields from file - each based on different criteria


use case when

for example, this will return the number of records that have Field1=0
Expand|Select|Wrap|Line Numbers
  1. select sum(case when Field1=0 then 1 else 0 end as result
  2. From TheTable
  3.  
There are better ways to do that.
It servers to illustrate CASE WHEN
Reply