Query Setup Help

E

esi

I have a tblpayroll table with the following fields:

tblpayroll
Period
Dept.
Hours Code
Hours

I also have 2 other tables

tbldept
dept.

and

tblperiod
period

I want to be able to see hours for every period and every dept. If a period
or dept has no hours, I want to see a "blank" in the query results. I can
do this with left joining 1 table but, not two and I have not been able to
setup 2 queries based on the way I want my data results.
 
L

Les

Hi,

Try doing the following:

1) Create new query with dept and period tables. This
should give you every combination of dept and period.

2) Create second query. As input to this query, use query
created above and payroll table. Join query to table by
period and dept. Make sure you left join from query to
table, because you want everything from dept/period query.

Hope this helps.
 
E

esi

Les,

I'm still not getting all the records I was expecting specifically, the
"blank" records.
 
L

Les

Did you get all depts and periods from the first query?
You should have.

The second query should have left joins on dept and period
fields, from query to payroll table.

Maybe you can post sql, if you still have problems.
 
L

Les

Also,
Be sure you select the dept and period from the query,
not the payroll table.
 
E

esi

Here is my sql for Q1

SELECT tblMonth.Month, tblMonth.Period, tblDepartments.[Department Number]
FROM tblMonth, tblDepartments;

and Q2

SELECT Q1.Period, Q1.[Department Number], Sum(tblPayroll2004.Hrs) AS
SumOfHrs
FROM Q1 LEFT JOIN tblPayroll2004 ON (Q1.[Department Number] =
tblPayroll2004.Dept) AND (Q1.Period = tblPayroll2004.Period)
WHERE (((tblPayroll2004.Code)="OTP"))
GROUP BY Q1.Period, Q1.[Department Number];

I wouls expect to see some blank fields for dept numbers w/ no "OTP" pay
code for some periods. This query is eliminating all the blanks. Thanks
for the help.
 
L

Les

Hi,
Whenever you use left joins, things don't work as you
would expect, when you have criteria based on the
table/query on the right.
Keep Q1 as is. Make a new Q2, based on your payroll
table. The only criteria you want here is Code="OTP".
Then, make a new Q3, which would left join Q1 and Q2 by
dept and period. Group and total the same way you did
before.
-----Original Message-----
Here is my sql for Q1

SELECT tblMonth.Month, tblMonth.Period, tblDepartments. [Department Number]
FROM tblMonth, tblDepartments;

and Q2

SELECT Q1.Period, Q1.[Department Number], Sum (tblPayroll2004.Hrs) AS
SumOfHrs
FROM Q1 LEFT JOIN tblPayroll2004 ON (Q1.[Department Number] =
tblPayroll2004.Dept) AND (Q1.Period = tblPayroll2004.Period)
WHERE (((tblPayroll2004.Code)="OTP"))
GROUP BY Q1.Period, Q1.[Department Number];

I wouls expect to see some blank fields for dept numbers w/ no "OTP" pay
code for some periods. This query is eliminating all the blanks. Thanks
for the help.
Also,
Be sure you select the dept and period from the query,
not the payroll table.


.
 
E

esi

Thanks Les....it worked perfect.

Les said:
Hi,
Whenever you use left joins, things don't work as you
would expect, when you have criteria based on the
table/query on the right.
Keep Q1 as is. Make a new Q2, based on your payroll
table. The only criteria you want here is Code="OTP".
Then, make a new Q3, which would left join Q1 and Q2 by
dept and period. Group and total the same way you did
before.
-----Original Message-----
Here is my sql for Q1

SELECT tblMonth.Month, tblMonth.Period, tblDepartments. [Department Number]
FROM tblMonth, tblDepartments;

and Q2

SELECT Q1.Period, Q1.[Department Number], Sum (tblPayroll2004.Hrs) AS
SumOfHrs
FROM Q1 LEFT JOIN tblPayroll2004 ON (Q1.[Department Number] =
tblPayroll2004.Dept) AND (Q1.Period = tblPayroll2004.Period)
WHERE (((tblPayroll2004.Code)="OTP"))
GROUP BY Q1.Period, Q1.[Department Number];

I wouls expect to see some blank fields for dept numbers w/ no "OTP" pay
code for some periods. This query is eliminating all the blanks. Thanks
for the help.
Also,
Be sure you select the dept and period from the query,
not the payroll table.


-----Original Message-----
Les,

I'm still not getting all the records I was expecting
specifically, the
"blank" records.


message
Hi,

Try doing the following:

1) Create new query with dept and period tables. This
should give you every combination of dept and period.

2) Create second query. As input to this query, use
query
created above and payroll table. Join query to table by
period and dept. Make sure you left join from query to
table, because you want everything from dept/period
query.

Hope this helps.

-----Original Message-----
I have a tblpayroll table with the following fields:

tblpayroll
Period
Dept.
Hours Code
Hours

I also have 2 other tables

tbldept
dept.

and

tblperiod
period

I want to be able to see hours for every period and
every
dept. If a period
or dept has no hours, I want to see a "blank" in the
query results. I can
do this with left joining 1 table but, not two and I
have
not been able to
setup 2 queries based on the way I want my data
results.


.



.


.
 
E

esi

Les,

What if I wanted to use Q1, Q2 based on payroll table with criteria of
Code="OTP" and Q3 based on payroll table with criteria of Code="REG" into a
new query, Q4. I tried to include Q1, Q2, and Q3 in a query left joining Q1
to Q2 and Q1 to Q3 but, received some duplicate record results. Any
suggestions

esi said:
Thanks Les....it worked perfect.

Les said:
Hi,
Whenever you use left joins, things don't work as you
would expect, when you have criteria based on the
table/query on the right.
Keep Q1 as is. Make a new Q2, based on your payroll
table. The only criteria you want here is Code="OTP".
Then, make a new Q3, which would left join Q1 and Q2 by
dept and period. Group and total the same way you did
before.
-----Original Message-----
Here is my sql for Q1

SELECT tblMonth.Month, tblMonth.Period, tblDepartments. [Department Number]
FROM tblMonth, tblDepartments;

and Q2

SELECT Q1.Period, Q1.[Department Number], Sum (tblPayroll2004.Hrs) AS
SumOfHrs
FROM Q1 LEFT JOIN tblPayroll2004 ON (Q1.[Department Number] =
tblPayroll2004.Dept) AND (Q1.Period = tblPayroll2004.Period)
WHERE (((tblPayroll2004.Code)="OTP"))
GROUP BY Q1.Period, Q1.[Department Number];

I wouls expect to see some blank fields for dept numbers w/ no "OTP" pay
code for some periods. This query is eliminating all the blanks. Thanks
for the help.
Also,
Be sure you select the dept and period from the query,
not the payroll table.


-----Original Message-----
Les,

I'm still not getting all the records I was expecting
specifically, the
"blank" records.


message
Hi,

Try doing the following:

1) Create new query with dept and period tables. This
should give you every combination of dept and period.

2) Create second query. As input to this query, use
query
created above and payroll table. Join query to table by
period and dept. Make sure you left join from query to
table, because you want everything from dept/period
query.

Hope this helps.

-----Original Message-----
I have a tblpayroll table with the following fields:

tblpayroll
Period
Dept.
Hours Code
Hours

I also have 2 other tables

tbldept
dept.

and

tblperiod
period

I want to be able to see hours for every period and
every
dept. If a period
or dept has no hours, I want to see a "blank" in the
query results. I can
do this with left joining 1 table but, not two and I
have
not been able to
setup 2 queries based on the way I want my data
results.


.



.



.
 
Top