Not sure how to do the totals queries. I've tried, and
can't get anything to work. Here's details: main table
is military personel. i have one query that selects
enlisted personnel. another query that select officer
personnel. for my report, I want the number of enlisted
and number of officer. I figured I could pull the total
from each of the established queries by using a control
source function.
It is nettique to post details, for example your DDL schema:
CREATE TABLE Personnel
(
personnel_nbr CHAR(10) NOT NULL,
last_name VARCHAR(35) NOT NULL,
personnel_type CHAR(8) NOT NULL,
CONSTRAINT pk__personnel PRIMARY KEY (personnel_nbr),
CONSTRAINT ch__personnel_type CHECK(personnel_type IN ('Enlisted',
'Officer')),
CONSTRAINT un__personnel_nbr_type UNIQUE (personnel_nbr,
personnel_type)
)
;
some sample data:
INSERT INTO Personnel
(personnel_nbr, last_name, personnel_type)
VALUES ('9226599520', 'Norarules', 'Officer')
;
INSERT INTO Personnel
(personnel_nbr, last_name, personnel_type)
VALUES ('1179537015', 'Hevitoxic', 'Officer')
;
INSERT INTO Personnel
(personnel_nbr, last_name, personnel_type)
VALUES ('2857727233', 'Regisaver', 'Enlisted')
;
INSERT INTO Personnel
(personnel_nbr, last_name, personnel_type)
VALUES ('6929845415', 'Livehulas', 'Enlisted')
;
and the DDL for your existing queries would've been a nice touch:
CREATE VIEW EnlistedPersonnel AS
SELECT personnel_nbr, last_name
FROM Personnel
WHERE personnel_type = 'Enlisted'
;
CREATE VIEW OfficerPersonnel AS
SELECT personnel_nbr, last_name
FROM Personnel
WHERE personnel_type = 'Officer' ;
;
Do you expect the reader to do all that work for you as well as some
up with a solution? <g>
You seem to want to do something like this:
CREATE VIEW TotalsByPersonnelType_Err AS
SELECT 'Officer' AS personnel_type,
COUNT(personnel_nbr) AS [Count]
FROM OfficerPersonnel
UNION
SELECT 'Enlisted' AS personnel_type,
COUNT(personnel_nbr) AS [Count]
FROM EnlistedPersonnel
;
However, it would be easier to just use the Personnel table:
CREATE VIEW TotalsByPersonnelType AS
SELECT personnel_type, COUNT(personnel_nbr) AS [Count]
FROM Personnel
GROUP BY personnel_type
;
Jamie.
--