Connecting Tech Pros Worldwide Forums | Help | Site Map

problem with count query

Newbie
 
Join Date: Jul 2007
Posts: 5
#1: Oct 20 '07
Hi,

I need a help.I want to get the count of a row

id fstday secday 3day 4day 5day

aaa P A P A A bbb A P P A P

In the above result i pasted two rows of data from my table.I want to get the count of each employee having values as 'p' .FOR EG

i want the result set as for userid aaa ------------------2 (Its having 2 P's)

and for userid bbb------------------3 (Its having 3 P's)

plse help me to find this

Regards
Nitha
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#2: Oct 20 '07

re: problem with count query


Question moved to SQL Server Forum.
iburyak's Avatar
Expert
 
Join Date: Nov 2006
Posts: 1,017
#3: Oct 20 '07

re: problem with count query


Try this :


Expand|Select|Wrap|Line Numbers
  1. select id, 
  2. case when fstday = 'P' then 1 else 0 end +
  3. case when secday = 'P' then 1 else 0 end +
  4. case when  3day = 'P' then 1 else 0 end +
  5. case when 4day = 'P' then 1 else 0 end +
  6. case when 5day = 'P' then 1 else 0 end Result
  7. from table_name 
Reply