wrestling with union query - it has the upper hand

MS Office Access

    Next

  • 1. help with count (maybe) in query
    I'm trying to create a query that will return the number of times the first 4 digits of a nine digiti number appear on a certain day such that the first column will contain unique day values defined by StartDate and EndDate and the remaining columns will contain the respective item counts from those categories on those days. In SQL: PARAMETERS [Start Date] DateTime, [End Date] DateTime; SELECT [Missent Table].RT, count(Left([Missent Table].RT,4)=1111) AS [Dallas RCPC I] FROM [Missent Table] GROUP BY [Missent Table].[Date Sent Out] HAVING ((([Missent Table].[Date Sent Out]) Between [Start Date] And [End Date])); All the data is in the same table (Missent Table). Using the above I get an error message and using the following I get the total of ALL categories (in every category) on a certain day: PARAMETERS [Start Date] DateTime, [End Date] DateTime; SELECT [Missent Table].[Date Sent Out], Count(Left([Missent Table].RT,4)=1111) AS [Dallas RCPC I] FROM [Missent Table] GROUP BY [Missent Table].[Date Sent Out] HAVING ((([Missent Table].[Date Sent Out]) Between [Start Date] And [End Date])); If I've omitted any requisite information, please let me know. Thank you in advance for the assistance.
  • 2. Crosstab Query with only 2 columns
    I know how to crosstab a query, however my problem is that my query has only 2 colums and crorosstab require at least 3 columns. This is what I have: Col1 Col2 a 21 b 12 c 30 I would like to use the data in Col1 column ad header as follow: a b c 21 12 30 How can be done? (FYI in reality col1 and col2 are numeric in my query) Thank you, Silvio
  • 3. Query using Checkbox State
    I have a form which has several checkboxes on it. Each check box is used to choose whether criteria such as 'live' or 'preferred' supplier information is displayed on the form. The default position i.e. 'true', for each of these swichboxes is to list only the 'live' or 'preferred' suppliers. This works fine. However, my problem is when the value is changed to 'false'. I expected to see ALL of the records whether the supplier was 'preferred' or not but only suppliers flagged as not preferred are displayed. How can I get all of the records to be displayed if there the relevant checkbox is not selected as 'true'? Hope this makes sense. Terry

wrestling with union query - it has the upper hand

Postby TWljaGFlbCBNYWM » Mon, 13 Feb 2006 21:56:27 GMT

I'm tracking occurances of clocking-in late, and unexcused absences in Access 
2002.  My data resides in two tables tblTardy and tblMissedShift.  I'm trying 
to automate the generation of letters of reprimand which state the total 
number of occurances.  One occurance is clocking-in late.  Another occurance 
is missing a shift with an unexcused absence -- however, missing consecutive 
days counts as ONE occurance (there is my problem).

For example:  I'm late to work Monday = one occurance.  I'm late Tuesday = 
two occurances.  I call in sick Wednesday = three occurances.  I call in sick 
Thursday = still three occurances (consecutive sick days only count as one 
episode).  I'm late Friday = four occurances.

tblTardy:
idxTardyID, intStaff, dtmClockIn, dtmStartTime

tblMissedShift:
idxMissedShiftID, intStaff, dtmClockIn, intReason

tblPersonnelData:  many fields.  The only one used here is a boolean field 
to indicate if the employee is active in our department (they are on our 
phone list).

tblStaff:  provides an indexed staff number and name.

I fumbled & blundered my way into the following UNION query:
SELECT tblStaff.chrStaffLastName, tblStaff.chrStaffFirstName, 
Count(tblTardy.dtmClockIn) AS CountOfdtmClockIn
FROM (tblStaff RIGHT JOIN tblTardy ON tblStaff.idxStaffID = 
tblTardy.intStaff) LEFT JOIN tblPersonnelData ON tblStaff.idxStaffID = 
tblPersonnelData.intStaff
GROUP BY tblStaff.chrStaffLastName, tblStaff.chrStaffFirstName, 
tblPersonnelData.bolPhoneList
HAVING (((tblPersonnelData.bolPhoneList)=True))
ORDER BY tblStaff.chrStaffLastName

UNION SELECT tblStaff.chrStaffLastName, tblStaff.chrStaffFirstName, 
Count(tblMissedShift.dtmClockIn) AS CountOfdtmClockIn
FROM (tblStaff RIGHT JOIN tblMissedShift ON tblStaff.idxStaffID = 
tblMissedShift.intStaff) LEFT JOIN tblPersonnelData ON tblStaff.idxStaffID = 
tblPersonnelData.intStaff
GROUP BY tblStaff.chrStaffLastName, tblStaff.chrStaffFirstName, 
tblPersonnelData.bolPhoneList
HAVING (((tblPersonnelData.bolPhoneList)=True));

This query lists a name with the total number of entries, for that person, 
in the table.  It's close, but not quite what I need.  Any solutions?  Need 
any more info?? Be gentle, I'm not an IT pro.  

Thanks,
Michael Mac



Re: wrestling with union query - it has the upper hand

Postby Rob Oldfield » Tue, 14 Feb 2006 07:55:12 GMT

Well if you turned up to work once in a while, then you might already have
it figured out.  (Sorry, can't resist the joke.)

What data are you storing regarding missed shifts?  One record for the
Wednesday, and one for the Thursday, or one record that contains a start and
end date?






Access
trying
occurance
consecutive
sick
=
Need



Re: wrestling with union query - it has the upper hand

Postby TWljaGFlbCBNYWM » Tue, 14 Feb 2006 19:06:28 GMT

issed shift info goes into tblMissedShift:
idxMissedShiftID(autonumber field), intStaff (identifies staff member from
tblStaff), dtmClockIn (date AND time of missed shift), intReason (identified
reason from tblReason - sick, bereavment leave, etc.).

Each record holds info on one missed shift.

I hope you can pull a rabbit out of the hat for me. Thanks.

"Rob Oldfield" wrote:


Re: wrestling with union query - it has the upper hand

Postby Rob Oldfield » Wed, 15 Feb 2006 03:50:01 GMT

mmm. Certainly not straightforward but I think I'm getting somewhere. But
one other question that I need to ask: if there's a weekend in the middle of
two missed shifts, then does that still count as one? Similarly, do you
have to take account of holidays? If someone misses a shift on Friday, the
Monday is a holiday, and then also misses Tuesday, is that also still just
one?


"Michael Mac" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
(identified
have
and
total
Tuesday =
in
one
field
our
tblStaff.idxStaffID
person,



Re: wrestling with union query - it has the upper hand

Postby TWljaGFlbCBNYWM » Thu, 16 Feb 2006 09:01:16 GMT

t is a 24/7 business. As far as our employer is concerned there is no such
thing as a holiday, or weekend. All days are the same. A little depressing
now that I think about it...pass the prozac, better living through chemistry.

Michael

"Rob Oldfield" wrote:


Re: wrestling with union query - it has the upper hand

Postby Rob Oldfield » Fri, 17 Feb 2006 06:23:06 GMT

n that case I think I have it.

Counting tblTardy is obviously straightforward - just a straight group
query. It's tblMissedShift that is the troublesome one. So.. on that...

Query M1 - just uses the DateValue function to strip out the time part of
the dtmClockIn. You could also use it to filter out and intReasons that
don't count for whatever reason.

SELECT tblMissedShift.intStaff, DateValue([dtmClockIn]) AS dt,
tblMissedShift.idxMissedShiftID
FROM tblMissedShift;

Query M2 - the tricky bit. A self join that only returns records which have
a corresponding record for the same person, but the day before. In effect,
a list of records which don't need to be included (because the person was
off the day before).

SELECT M1_1.idxMissedShiftID, M1_1.intStaff
FROM M1 INNER JOIN M1 AS M1_1 ON M1.intStaff = M1_1.intStaff
WHERE (((DateDiff("d",[m1].[dt],[m1_1].[dt]))=1));

Query M3 - then just a standard subtract query to remove those records that
appear in M2 from the original list. The date returned will be the first
shift in a set of absences.

SELECT tblMissedShift.idxMissedShiftID, tblMissedShift.intStaff,
tblMissedShift.dtmClockIn
FROM M2 RIGHT JOIN tblMissedShift ON M2.idxMissedShiftID =
tblMissedShift.idxMissedShiftID
WHERE (((M2.idxMissedShiftID) Is Null));


From there, you can work out a total amount from the two types in various
ways.


"Michael Mac" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
such
depressing
chemistry.
But
middle of
the
just
from
already
the
start
message
absences in
I'm
call
count as
boolean
on
tblStaff.idxStaffID =
tblStaff.chrStaffFirstName,
solutions?



Re: wrestling with union query - it has the upper hand

Postby TWljaGFlbCBNYWM » Fri, 24 Feb 2006 13:46:29 GMT

ou did it!! Thank you so much. I beat my head against the wall for weeks
trying to figure this out. Hats off.

You are either an Access/SQL genius, or possibly just twisted enough to
figure this out.

"Rob Oldfield" wrote:


Similar Threads:

1.Close Button "X" on upper right hand corner of form

Hello all,

I have a question.  Sometimes when I open a form using VBA code and then 
type in "docmd.maximize" to maximize the form screen -- sometimes the "X" 
disappears.  Does anyone know why this happens AND how to fix it?

Thanks,
MN

2.program the close Access button on the upper right hand corner of the screen

How to I connect an event to the close Access button (white X on red square) 
.
The idea is when the user clicks this he will get a warning with the option 
to cancel before Access closes out completely 


3.program the close Access button on the upper right hand corner of

4.To union query or not to union query

Win XP Pro
Access 2002 XP

I am working in a Payment form which allows users to apply a payment to an 
invoice.  The form has a combo box named Payment Method.  I am currently 
using a Value List to populate the combo box ("Cash";"Check";"Credit 
Card";"Project Dep.";"House Credit").

I am adding new functionality to this application by tracking the balance of 
Project Deposits and Account credits.

What I want to end up with . . .
I want a combo box that displays each of the Payment Type entries it always 
has.  I also want it to have a second column where it lists the available 
funds beside the Project Deposit and Account Credit.

I want the other Payment Types to have nothing in the second column, or if I 
have to settle I will accept $0.00.

I have the queries built to return a balance per invoice number (separate 
query for each of the two types of payment).

How do I put these queries together to get the result I want?

I have considered creating a union query where I have the two output fields 
mentioned and the invoice # (need it to enter a where statement to return the 
proper balance for the Project Deposit and Account Credit).  For each of the 
other payment types not returning a balance I planned on having the Invoice#, 
PaymentType: "the text value currently in the Value List" and Amount: Null.

I am not sure if this is the best way to accomplish this or if I have over 
thought so bad and made it 10 times harder than it really is.

Thanks,

Seth

5.convert upper case text to lower case with the first letter upper

How do I convert text that is in all upper case to lower case with the first 
capitalized

6. Union query help - multiple unions

7. Is there a limit on Union query unions?

8. UNION or UNION ALL query question



Return to MS Office Access

 

Who is online

Users browsing this forum: No registered users and 66 guest