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)
 Case Statement

Author  Topic 

charul
Starting Member

18 Posts

Posted - 2008-10-17 : 01:46:37
I have a query like this
Select ORG4 as [ORGDESC],[CONFIRMED IN MONTHS],
Count(*) as Counts from Confirmation_Details
WHERE [EMPLOYEE CODE] IS NOT NULL group by
ORG4,[CONFIRMED IN MONTHS]

The output is like below

ORGDESC CONFIRMED IN MONTHS Counts
Common 0 2
Common 02 2
Common 03 31
Common -03 5
Common 13 8

I need to modify the query such that
for [Confirmed in Months] less than 1 , the sums should add up
and for greater than 12 , the sums should add up

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-17 : 02:12:30
[code]SELECT org4 AS orgDesc,
CASE
WHEN confirmedInMonths < 1 THEN 'A'
WHEN confirmedInMonths > 1 THEN 'B'
ELSE confirmedInMonths
END AS confirmedInMonths
COUNT(*) AS Counts
FROM confirmationDetails
WHERE employeeCode IS NOT NULL
GROUP BY org4,
CASE
WHEN confirmedInMonths < 1 THEN 'A'
WHEN confirmedInMonths > 1 THEN 'B'
ELSE confirmedInMonths
END[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

charul
Starting Member

18 Posts

Posted - 2008-10-17 : 02:29:31
Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-17 : 02:38:20
ooops!

> 1 should be > 12

Sorry...



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -