Display data horizontally in MS Access report - sql

I am currently working with a MS Access database, which should store courses and their participants. Each course has multiple course days and I want to create a report on which the teacher can tick (if printed out) if the student is attending the current lesson.
Therefore I would like to display the names of the participants vertically and the course dates horizontally, but I got stuck at this point.
Like in the screenshot here:

Related

Filtering access control data to get list of people inside office

I would like to create an SQL query for a "Role Call" which would show me the people who are inside the building only. Each person has his own access card and has to go in or out of the building using 1 of 4 turnstiles. So far I managed to retrieve the 4 turnstiles (in and out) data for todays date. I need to filter the list to only show people who had an "in" entry but did not leave yet. People can come and go as they please and use any of the 4 turnstiles and have multiple "ins" and "outs" per day.
I am bit stuck here how to do this.
I am joining 2 tables which have the device information (turnstiles) and the log of all swiped cards. I am filtering for the turnstiles data only and todays date.
SELECT [dbo].[lACLog].[LogID],[dbo].[lACLog].[LogDate],[dbo].[lACLog].[DeviceAddress],[dbo].[pPeriphery].[Name],[dbo].[pPeriphery].[PeripheryUID],
[dbo].[lACLog].[CardNr],[dbo].[lACLog].[Name],[dbo].[lACLog].[PersonalNr],[dbo].[lACLog].[PersID]
FROM [dbo].[lACLog]
LEFT JOIN [dbo].[pPeriphery]
ON [dbo].[lACLog].[DeviceAddress]=[dbo].[pPeriphery].[DeviceAddress]
WHERE [dbo].[lACLog].[LogDate]>=CAST(GETDATE()AS Date) AND [dbo].[pPeriphery].[PeripheryUID]
IN ('2130B72E-D8E9-4269-B6B0-68BEC95CB483',
'9229D4B6-5CD7-43E6-B7C7-BF9779333521',
'919C5D57-5885-460A-8679-D0C257837D82',
'C45B8C65-FF46-42FA-B428-E01853DEB65E',
'550669EC-2BC4-4008-A1A7-469E9C5266C5',
'3C843DFA-CFE3-4E01-93E9-ADE50A2D5BED',
'FB6736AA-2940-497F-A367-5BB0308F4B77',
'E6EE768E-1587-41EF-B7FD-B61A14BA9395');

SQL select statement for generating form letters

I currently have a database in MS Access that I need to update the way we generate form letters.
We use a query I made 10 years ago to generate certificate of attendance letters.
SELECT doctors.address, seminar_title, seminar_date, first_name, last_name
FROM doctors, seminars, registrations
WHERE seminars.seminar_id=[Seminar] AND registrations.seminar_id=seminars.seminar_id AND
registrations.dr_id=doctors.dr_id
ORDER BY doctors.last_name;
The result is a set of letters for whatever seminar ID you enter. Each letter representing an individual registration by a doctor.
The issue now is that we have an additional table (Licenses), and I need each letter to display 1 to 5 licenses that a doctor might have.
The fields in the Licenses table are: license_ID, doctor_id, license_type, state, and license_number.
I can display one license, but getting a varying amount of license numbers and states to display, each matched on a letter to its licensee, has been beyond what I know how to do so far.
Any input is appreciated.
You'll want to create a subreport listing all of the licenses for the doctor the letter is addressed to. First you will need a table linking doctors to the licenses they have (e.g. "doctor_licenses"), with the fields dr_id and license_id. Add doctors.dr_id to your query above so it is part of the recordsource for your main report. Then create a second report to display the licenses for each doctor. The recordsource for your second report will be something like
SELECT dr_id,
license_type
FROM doctor_licenses
INNER JOIN licenses
ON doctor_licenses.license_id = licenses.license_id
Add the second report to your main report as a subreport. Link the subreport to your the main report by setting its "Link Master Fields" and "Link Child Fields" properties both to dr_id. More info on subreports and how to create and use them here:
https://support.microsoft.com/en-us/office/create-and-use-subreports-816f987a-4615-4058-8f20-ce817093bb33
EDIT because I can't comment on your original post, you'll still need to use a subreport to list doctor licenses as there is a one-to-many relationship between doctor and licenses (one doctor can have one or more licenses). If you're trying to add the list of licenses as a comma delimited list or something similar to your report you'll have to utilize a more complicated approach. Please look at the subreport solution and if that doesn't do what you need please be more specific about your requirements.

Using Delphi TChart to display information from a database

I want to create a pie chart in Delphi that will show the user the number of people who play a specific sport.
The following SQL statements gets the information from the database and stores the number of people in a variable. The data type in the database is yes/no, so those who play a specific sport will have a tick and those who don't won't. The sql statement will determine how many people play a specific sport (if there is a tick in the database)
qry.sql.clear;
qry.sql.add('SELECT Count(tennis) AS [NoTennis] FROM [Sports] WHERE Tennis = True');
qry.Open;
iTennis := qry['NoTennis']; {integer variable}
This repeats for all the other sports, such as swimming, hockey, etc
Afterwards this data must be represented in the pie chart. I have the following code...
Chart1.Series[0].AddXY(iTennis, 1, 'Tennis', clTeeColor);
This also obviously repeats for all the other sports. But instead of displaying my data during run time, it still displays random data about keyboards and motorists, etc. To see what I am talking about click
(source: asiplease.net)
How do I get TChart to change it's data? Is it the SQL statement or adding the x and y values that is causing the problem?
You are showing a pie chart. The chart type is relevant how you add data to the chart. I remember thas AddXy was only for line-based chart. Try
Chart1.Series[0].Add(123, 'Tennis');
See steema documentation.
To clear previously generated values of the series, use
Chart1.Series[0].Clear();

SQL query for game rental website - game delivery report

http://sqlfiddle.com/#!3/f2da70/13
I am creating a game rental website using MS SQL 08 and I have to create a report which will give me a list of all the games that need to be posted and to who.
This query will have to go through different stages:-
List the users that have not reached their game quota for that month based on the subscription package they have chosen and rental table.
Compare this list of users to their favourites list and asign a game to them based on what game is their highest priority and by date.
The game or games selected must be in stock which needs compared to quantity levels in games table.
I have a SQL query but it is not taking into consideration the dates that a user added a game to their favourites list, it works solely on priority level. I need to change this query so it picks the oldest date added if the priority of the games are the same. In this sample data in SQL Fiddle it should be giving me barcode 27 to match with Need for Speed Rivals but it is giving me FIFA 14 as it is the first favourite record it sees.
Also the report needs to show more than the game barcode, it needs to show user name and game details. It is also only working for a single user at the moment with with me entering a user ID manually but it should just go through all users.
If anyone can help me with this query it would be much appreicated it, just really dont know where to go from here.
change
ORDER BY Favourites.Priority
to
ORDER BY Favourites.Priority, Favourites.DatePicked asc

MS Access- Table normalization and query design problems

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.