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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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





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

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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/28/2008 :  05:44:21  Show Profile  Reply with Quote
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000