Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Report query
I am trying to create a query which should return 4 columns
Facility  |  NoOfActiveApplicants
 |  NoOfArchivedApplican
ts | TotalApplicants
I would be glad to even have just 3 columns since, the Total can be computed
in the display table (ColdFusion interface)

Facility  |  NoOfActiveApplicants
 |  NoOfArchivedApplican
ts

So far I have the following query, which returns just 2 rows with both
 NoOfActiveApplicants
 &  NoOfArchivedApplican
ts under the same column.
Am stuck here, any help is apprecialted.  Thanks in advance!

select
NoOfApplicants= sum(case when a.id <> 0 then 1 else 0 end)
, Facility = case when c.facility is null then c.JobDBFacilityName else c.
facility end
from tblapplicant a, tblJobDB b, tblfacilities c
where a.jobid = b.jobid
and b.facility = c.facilityid
group by c.facilityid,c.JobDBFacilityName,c.facility,b.facility
union all
select
NoOfApplicants= sum(case when a.id <> 0 then 1 else 0 end)
, Facility = case when c.facility is null then c.JobDBFacilityName else c.
facility end
from tblArchiveapplicant a, tblArchiveJob b, tblfacilities c
where a.JobVacancyNumber = b.JobVacancyNumber
and b.facility = c.facilityid
group by c.facilityid,c.JobDBFacilityName,c.facility,b.facility
order by facility

Report this thread to moderator Post Follow-up to this message
Old Post
c0de w via webservertalk.com
07-28-05 01:23 AM


Re: Report query
On Wed, 27 Jul 2005 19:28:42 GMT, c0de w via webservertalk.com wrote:

>
>I am trying to create a query which should return 4 columns
>Facility  |  NoOfActiveApplicants
 |  NoOfArchivedApplican
ts | TotalApplicants
>I would be glad to even have just 3 columns since, the Total can be compute
d
>in the display table (ColdFusion interface)
>
>Facility  |  NoOfActiveApplicants
 |  NoOfArchivedApplican
ts
>
>So far I have the following query, which returns just 2 rows with both
> NoOfActiveApplicants
 &  NoOfArchivedApplican
ts under the same column.
>Am stuck here, any help is apprecialted.  Thanks in advance!
>
>select
>  NoOfApplicants= sum(case when a.id <> 0 then 1 else 0 end)
>, Facility = case when c.facility is null then c.JobDBFacilityName else c.
>facility end
> from tblapplicant a, tblJobDB b, tblfacilities c
>where a.jobid = b.jobid
>  and b.facility = c.facilityid
>group by c.facilityid,c.JobDBFacilityName,c.facility,b.facility
>union all
>select
>  NoOfApplicants= sum(case when a.id <> 0 then 1 else 0 end)
>, Facility = case when c.facility is null then c.JobDBFacilityName else c.
>facility end
> from tblArchiveapplicant a, tblArchiveJob b, tblfacilities c
>where a.JobVacancyNumber = b.JobVacancyNumber
>  and b.facility = c.facilityid
>group by c.facilityid,c.JobDBFacilityName,c.facility,b.facility
>order by facility

Hi c0de,

Hard to say without knowing anything about structure of the tables in
your database (see www.aspfaq.com/5006 for a better way to ask questions
in these groups). But you might see if the following helps you:

SELECT   Facility,  NoOfActiveApplicants
,  NoOfArchivedApplican
ts,
 NoOfActiveApplicants
 +  NoOfArchivedApplican
ts AS
TotalApplicants
FROM    (SELECT COALESCE(facility, JobDBFacilityName) AS Facility,
(SELECT     COUNT(*)
FROM       tblapplicant AS a
INNER JOIN tblJobDB AS b
ON   a.jobid = b.jobid
WHERE      b.facility = c.facilityid) AS
 NoOfActiveApplicants
,
(SELECT     COUNT(*)
FROM       tblArchiveapplicant AS a
INNER JOIN tblArchiveJob AS b
ON   a.JobVacancyNumber = b.JobVacancyNumber
WHERE      b.facility = c.facilityid) AS
 NoOfArchivedApplican
ts
FROM   tblfacilities AS c) AS der
ORDER BY Facility

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
07-28-05 01:23 AM


Re: Report query
Hi c0de ,
As Hugo correctly pointed out (see www.aspfaq.com/5006 for a better
way to ask questions in these groups). As a friendly advice please do
post DDL,DML as it become easier for others to test their queries .

All I can see you wish to prepare a report which can be done using
corelated subquery (I can be wrong because I am not having data with me
to check the correctness of my query)

Select F.facilityid,
(select count(*) from tblapplicant a, tblJobDB b where a.jobid =
b.jobid and b.facility=F.facilityid),
(select count(*) from tblArchiveapplicant a, tblArchiveJob b where
a.JobVacancyNumber = b.JobVacancyNumber and b.facility=F.facilityid)
from tblfacilities F

May this query solve your problem. As an another advice please use same
column name in all tables that are to be linked (related) .

With warm regards
Jatinder Singh


Report this thread to moderator Post Follow-up to this message
Old Post
jsfromynr
07-28-05 08:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 12:18 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006