Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 urgent help

Author  Topic 

abcd
Yak Posting Veteran

92 Posts

Posted - 2008-11-28 : 02:00:36
my problem is as follows....

i am having a result set containing columns

userid,

deptname,

leavetype,

ismispunched,





where leave type can be of three categories

normal,on duty and on tour



now i want to display userid,deptname and in seperate columns how many times user went on -on duty,normal or was on tour





basically problem is how to compare column value in a table with a given criteria and display it in a seperate column

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-11-28 : 03:02:43
SUM(CASE leave WHEN 'normal' THEN 1 END 0 END) AS TotalNormalLeave

Repeat for the the other two and then group by userid,deptname

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-28 : 05:44:21
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115041
Go to Top of Page
   

- Advertisement -