I have a timecard file that list the daily hours for each employee. I have figured out, using a query, how to get the total number of hours but I also need the total number of employees. I have searched here and on other places and tried just about everything and nothing works. I am sure it is something pretty simple but I just cannot seem to get the total number of employees. Any help will be greatly appreciated.
The main file is called Timecards and I link to a file call Employees using the field employee number to get the employee name. There are other fields in Timecards namely "Job No", "Job Description" and "Type of Hours"( such as regular and overtime) that I wanted on the summary report but I did not realize that a employee could have two entries in those fields. So that is why I could not get the total employees to come out right when using those fields.
I was finally able to create a query and print a report with the total employees using fields that only appear once in the Timecards file. So unless someone knows how to count total lines is a report I will stick with the report I have that works.
I agree with Vladimir, it helps to post what you expect to see and what kind of tables you are working with. However, I have been in the same situation. Maybe this is a good starting point in SQL
SELECT COUNT(*) AS TotalNumberEmployees FROM TheTableShowingEmployees;
Posting a question with:
A problem statement
A list of expected results
Sample Code tried
Table structures involved (Including relevant fields, data types, and tableNames)
Will get you better results. Show your work, we'll show you ours!
Given limited information so far this is the best I can come up with
I use a left join incase some of the employees haven't reported hours yet and you want all employees.
I use coalesce to change null hours to 0.
I assume that Employees Table exists and it joins to timecard on Employee_no.
I assume firstName and LastName are in the
employeetable
.
SELECT coalesce(Sum(T.hours),0) AS SumOfhours, E.FirstName, E.LastName
FROM Employees E
LEFT JOIN Timecards T
on T.Employee_no = E.Employee_no
GROUP BY E.FirstName, E.Last_name
Also note you can edit your question don't comment on it; it makes it difficult to follow.. and last but not least .... Welcome to SO!
Well after much searching and testing I finally found a post from 2009 that took care of my problem.
`If you want to count groups, you might need to add a running sum text box in
the group header. For instance, if your report contains orders and order
details but you want to count the number of unique orders, you can't use a
text box in the report footer with a control source like:
=Count(OrderID)
This expression will count orders and details.
You can add a text box in the Order header:
Name: txtOrderCount
Control Source: =1
Running Sum: Over All
Visible: No
Then add a text box in the Report Footer section:
Control Source: =txtOrderCount
Duane Hookom
Microsoft Access MVP`
Thanks for all the help.
Related
I have these three tables:
I need to list staff names and the number of projects they have worked on, I'm not really sure how to do this. Right now I'm able to list all the staff members who have worked on a project using this:
SELECT staff.s_name FROM Staff staff
INNER JOIN Work_on work ON staff.s_id = work.s_id
INNER JOIN Projects proj ON work.p_id = proj.p_id
And this displays the names of all the people who have worked on a project, some names are listed twice, indicating how many projects they've worked on. I don't know how to list this as a separate value though and display both their names and the number of projects they've been working on, obviously I'd need to use the COUNT() function somewhere but I don't know how to count everytime a name appears from the result. Could someone provide me a tip of sorts?
The result is supposed to look like this:
Right now I'm only getting this:
Which is correctly displaying how many times a user has worked on a project, but I don't know how to use this to create another column displaying the count.
Would it help?
SELECT staff.s_name, count(1) FROM Staff staff
JOIN Work_on work ON staff.s_id = work.s_id
GROUP BY staff.s_name
If I was given a question in an exam, where I would explain a piece of code from Microsoft Access SQL Query, without any external data or information.
How would I explain the following code in simple/plain English, I just want to get an idea because this is my first time explaining a code:
SELECT last_name, department_id, job_id
FROM employees
WHERE department_id IN
(
SELECT department_id
FROM departments
WHERE location_id = 1700
);
Is this a good explanation to a layman:
The following code: asks us to list employees' last name, their job at each department and their job identity. For each department that has a location ID equals/equivalent to '1700'. Would this be a great explanation?
SQL means Structured Query Language. Another word for "Query" is just "Question". Just about every query is written to provide a set of data that answers a question.
When you're explaining a code sample, or trying to figure out some code you inherited for that matter, a good place to start is to start by trying to figure out what question the results of the query were intended to answer. If you were sitting at your computer and somebody came up and asked you a question, what question would that be that would result in you writing that block of code? Oftentimes, just that question alone is enough of an explanation for a layperson.
Here, I'd say a fair start would be something along these lines.
This code answers the question, "What are the last names, department IDs and job IDs of everyone whose department is at location 1700?"
When giving a technical explanation, you take it to the next step. How does this code go about answering the question that was asked? This is the nuts and bolts of how the query works, as opposed to what it's supposed to do.
So, technically:
This code uses a sub-query against the departments table, which includes a location_id column, to identify all the departments at location_id = 1700. Then it uses the department list from the sub-query to get the last_name and job_id data from the employees table, using the department_id list as a filter.
As per my point of view, you need to explain the following thing
This query type is a subquery
This query provides the employee list.
This employee list is base on department and only those department need to consider which location id is 1700
So in a short way, you can say like this query give a list of employee which work on the specific location.
I hope you got this answer as correct answer.
I think a pithier explanation would be along the lines:
Fetch certain information about employees whose department is at location 1700.
I have two tables
Email Contact History
Place of Service
that share a primarymembercustomerid. The Email Contact History has three fields:
Campaigncode
Primarymembercustomerid
maildate
and the Place of Service table has three fields
primarymembercustomerid
servicedate
serviceshortDesc
primarymembercustomerids are selected for E-mail campaigns, then if they walk into one of our branch offices and receive services, they show up in the Place of Service table. I want to count the number of primarymembercustomer ids that are mailed, and right next to it I want to have a count of primarymembercustomerids that showed up to a branch office.
What I have so far:
select
ch.campaigncode,
pos.serviceshortdesc,
count(ch.primarymembercustomerid),
count(pos.primarymembercustomerid)
from mktprodvm.cdmv_prmmbr_contacthist_email ch
right outer join mktprodvm.cdmv_pos pos on ch.primarymembercustomerid = pos.primarymembercustomerid
where ch.campaigncode = 'EDT_ALLACMO'
and pos.servicedate between '2017-02-01' and '2017-02-28'
group by 1,2
What I'm ending up with is a count of primarymembercustomerids that walk into a branch for that time period, but I'm not getting the total count of primarymembercustomerids that were E-mailed. I thought that by doing a right outer join I would get the total number of primarymembercustomerids that were mailed, but it's not working for me. I feel like I need to do some kind of subquery or correlated subquery, but I've ready about how to use them and I don't think that's right. I've never used them before and to be quite honest I'm not that great of a SQL coder either. Thanks for any help!
Because my low reputation on this site I can't comment, so I'm writing this as an answer.
I think that you are using the wrong type of join (or writing the tables in the wrong order). If you don't want to lose rows of your main table, the Email Contact History, you have to do a LEFT JOIN not a RIGHT JOIN.
Also, I don't know if it's possible, but I'm guessing that a primarymembercustomerid can have more than one service and since you are selecting the serviceshortdesc, a single Email might count in different rows of your anwerset and the total won't be accurate. According to what you said you want, I don't see a reason for including the service description in the SELECT.
I have a tricky thing I'm trying to get working
I have a table that contains events, and 10 fields populated with ID Numbers of employees who attended, and a comment box for each one. I tried to create a query that uses a combo-box with the ID Number to Search for the events they attended, and display them in a form cleanly (IE without displaying other peoples, or having a large number of text boxes everywhere). I got it partially working but I could not figure out how to go any farther. I can't figure out how to separate out the fields by the people. I was toying with the idea of having the event listed say 10 times with one person per record but that would cause alota bloat.
Any ideas how to do this? Different formats/other approaches would be great as well.
Thanks guys.
I would split the tables... have one that contains the event, with an eventID field as an AutoNumber. Then have another table called Attendance with three fields: eventID containing the ID of the event, employeeID, and Comment for the comment. This would then even allow you to create another table containing more info about the employee like first name and last name for use in reports.
I'm trying to do something that I thought ought to be reasonably simple but I keep failing... Maybe I just need more coffee, but I thoguht i see if anyone else has solved the problem already.
I've got a report, it contains a pile off rows.
I want the row to show up grouped by one column called office.
I want the groups of offices sorted by their column region.
I want the rows within the office group sorted by column name.
so it'd show up like this
Region1
Agency a
a
b
c
Agency b
a
b
Region 2
Agency a1
a
b
c
etc...
I can get the grouping, I can get the groups sorted by region.
but I can't get the contents of the group to be sorted by name.
my curret guess was Group by Office
then in the sort tab, sort by region, then office, then name. no joy.
Any help is appreciated.
if it's relavant I'm using c# and vs2008.
Thanks,
E-
I often have problems with sorting in the rdl/rdlc and end up having to sort the data that is coming to the report to get it to show up correct. Also sometimes it helps if you add sorting on every group. So for your Region group you'd add all the sorting. Then on the Office Group also add sorting.
Try putting the sort in the table, it worked for me