SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 urgent help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

abcd
Yak Posting Veteran

92 Posts

Posted - 11/28/2008 :  02:00:36  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

South Africa
4507 Posts

Posted - 11/28/2008 :  03:02:43  Show Profile  Visit GilaMonster's Homepage  Reply with Quote
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

India
52317 Posts

Posted - 11/28/2008 :  05:44:21  Show Profile  Reply with Quote
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115041
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000