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)
 Help with a query

Author  Topic 

Karen426
Starting Member

3 Posts

Posted - 2008-10-30 : 16:27:32
Hello All. I need some help. I am new to Transact SQL so this maybe very easy for some. I have a query that is pulling counts.
I have listed my code so far. This query gives me the individual counts for each group then I need to take the counts from Intakes and Enrollments to get TotalA and then I need to add TotalA to Fax Referrals and General Inquires to get TotalB. Can someone please help me?

Thank You.

(select count(*)as "Fax Referrals"
from
Referral a
inner join client b on
b.clientprogramid = a.clientprogramid
where
a.referral_type = 'FAX'
and b.clientprogramname = 'ClientA'
)
(select count(*) as "General Inquiries"
from person a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
b.clientprogramname = 'ClientA'
)
(select count(*)as "Intakes"
from Calls a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
c.clientprogramname = 'ClientA'
)
(select count(*)as "Enrollments"
from person a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
b.clientprogramname = 'ClientA'
)

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-30 : 17:43:18
Here's a lazy query for you:

select [Intakes]+[Enrollments] as TOTALA, [Fax Referrals]+[General Inquiries] as TOTALB
from (
select
(select count(*)
from
Referral a
inner join client b on
b.clientprogramid = a.clientprogramid
where
a.referral_type = 'FAX'
and b.clientprogramname = 'ClientA'
)as "Fax Referrals",
(select count(*)
from person a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
b.clientprogramname = 'ClientA'
)as "General Inquiries",
(select count(*)
from Calls a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
b.clientprogramname = 'ClientA'
)as "Intakes",
(select count(*)
from person a
inner join clientprogram b on b.clientprogramID = a.clientprogramid
where
b.clientprogramname = 'ClientA'
) as "Enrollments"
)t
Go to Top of Page
   

- Advertisement -