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 2008 Forums
 Transact-SQL (2008)
 Query Problem

Author  Topic 

SQLNoob81
Starting Member

38 Posts

Posted - 2011-07-14 : 03:37:18
Hi
I have the following Query and it works fine. It shows me the monthly value of order received.

select Month(Recieved) as MI, DateName(Month,Recieved) as mm , Sum(Fee) as amt
from JobOrder

where year(Recieved) = @Year
and Consultant = @Branch
group
by month(Recieved)
, DateName(Month,Recieved)
Order by Month(recieved)


I need to also retrieve the value of orders placed as below


select Month(Recieved) as MI, DateName(Month,Recieved) as mm , Sum(Fee) as amt,Sum(fee) as amtPlaced where result='Placed'
from JobOrder

where year(Recieved) = @Year
and Consultant = @Branch
group
by month(Recieved)
, DateName(Month,Recieved)
Order by Month(recieved)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-14 : 03:40:39
[code]sum(case when result='Placed' then Fee else 0 end)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SQLNoob81
Starting Member

38 Posts

Posted - 2011-07-15 : 06:46:59
Thanks. Worked like a treat!!!!
Go to Top of Page
   

- Advertisement -