I am currently working on fingerprint-based student attendance system. I am using Arduino Uno and fingerprint sensor to get student attendance record and store in SQL Server. I have a table called Attendance in my database which is storing student attendance records.But I have a problem with that.
Lets say Student A is absent today, the attendance record will not be stored in table Attendance for Student A. Meaning that I can only show students who are present to school today, the attendance record for Student A cannot be shown to the teachers.
Teachers can only view student attendance record after selecting the date, Student A attendance record cannot be seen by teachers cause there is no records for Student A in table Attendance
So How can I solve this? Any suggestion or reference? Your help is appreciated. Thank you
Assuming you're passing in the date as a parameter, you can just left outer join to the attendance table, and put the date check in the on clause (as opposed to the where clause. Putting it in the where clause effectively turns a left outer join into an inner join, due to the order in which the query is parsed and executed.
select *
from [student] s
left outer join [attendance] a
on s.[id] = a.[id]
and a.[attendanceRecordDate] = #date
SELECT *
FROM STUDENT
LEFT JOIN ATTENDANCEMARK
ON STUDENT.ID = ATTENDANCEMARK.STUDENTID
WHERE ATTENDANCEMARK.DATE = #DATE OR ATTENDANCEMARK.DATE IS NULL
Explanation: you are looking to list all students with today's attendance mark, but want to list all students even if they have no attendance mark.
Related
In my database currently, have 2 tables with data called student and subject.
In my web application have a new requirement, so I have to add additional mapping table called StudentSubject. However now I need to insert data to that table(StudentSubject) as follows. How can I write a script to achieve it? And may I know should I need to write Pre-Deployment or Post-Deployment Script to do this? If yes how can I do it?
Simple by cross Join.
INSERT INTO StudentSubject
SELECT StudentId, SubjectId
FROM Student, Subject
--OR
INSERT INTO StudentSubject
SELECT StudentId, SubjectId
FROM Student
CROSS JOIN Subject
I am making an attendance management system where users/employees can mark their attendance once a day. The admin can see the overall attendance of the employees. I have to show this in a tabular form.
I have made 2 tables in SSMS: tblUser and tblAttendence. tblUser contains RegNo(int), Name(varchar) and JoiningDate(date). tblAttendence has DateAndTime(datetime) and RegNo(int) as columns. So whenever a user opens the application and marks the attendance, it will be recorded in tblAttendance with the current DateTime and the RegNo of the user.
Now, I have to display this using a DataGridView with the columns as RegNo, Name and Attendance(this will be the number of entries found in tblAttendance corresponding to the RegNo)
Can this be done? I can't seem to find out a way to do this. Is there a way to do it?
You can obtain the count of the attendances by user with
SELECT u.RegNo, u.Name, Count(t.RegNo) AS Attendance
FROM tblUser u JOIN tblAttendance t ON u.RegNo = t.RegNo
GROUP BY u.RegNo, u.Name
and if you like an order you can add
ORDER BY Count(t.RegNo) DESC
I am not sure if I titled this question correctly, here is my question. I have a table that has Products and these products have various details including buying price, selling price, initial stock quantity, number of items sold, number of items remaining. I then have another table with sales information based on location of the buyer lets call it LocationSales. I need to create a table that will show the products and the location information like in the snapshot below.
I made the representation using Excel. I had already achieved this while working on a project earlier last year but it involved a lot or hard-coding and stack-overflow exceptions. I would like to achieve this more effectively. This is a hypothetical representation of my actual problem. I have tried using hierarchical tables before using Telerik UI which worked well but did not display the information quite as required by my superiors. I would really appreciate it if someone would point me to the right direction. I understand it's impossible to address the entire problem here but I would appreciate someone including a link to a blog post or video or some literature that can assist me. PS. I have tried database views as well, didn't work as required.
I am using ASP.NET C# MVC5 with Visual Studio 2013 and the database as SQL Server 2012
EDIT://Tables I am using
EDIT 2:///
As per my research so far i have managed to obtain the following
SQL CODE://
select * from
(select
locationName
,productName as [PRODUCT]
,roadTransfer
,airTransfer
,initialQty
,soldQty
,remQty
from
Location as l inner join
Sales as s on l.locationID=s.locationID
inner join
Product as p on p.productID=s.productID
)as BaseData
pivot(
count(roadTransfer)
for locationName
in([Germany]
,[Kenya]
) as SummaryTable
order by Product asc
I used a pivot table. I am currently trying to get both the road and air transfer. I I will try using a GROUP BY clause and see what I can do. I will post an update when I have the full solution.
So at this point (Edit 2) you have created a pivot for road transfer. Unfortunately you can't aggregate more than one value in a pivot, so the way round it is to do two pivots and join the results together. You result set therefore has 3 query parts to produce the query
A list of products
Pivoted Road Transfer amounts by country
Pivoted Air Transfer amounts by country
If you left join all of them together in a single query on the product ID you will get close to your query, but the column order won't be quite right i.e. all the Road Transfers will come before the Air Transfers.
I have created a SQLFiddle demonstrating this
Select p.prodName AS Product,
p.initialQty AS [Initial Quantity],
p.sold AS [Quantity Sold],
p.remaining AS [Quantity Remaining],
AirT.[Air Transfer - Germany],
RoadT.[Road Transfer - Germany],
AirT.[Air Transfer - Kenya],
RoadT.[Road Transfer - Kenya]
FROM Products p
LEFT JOIN (
SELECT productID, [Germany] AS [Air Transfer - Germany], [Kenya] AS [Air Transfer - Kenya]
FROM (select productID, l.locName, qty
FROM sales s
INNER JOIN Locations l on l.locID = s.locID
where transfer = 'Air Transfer') as SourceTable
PIVOT (SUM(qty)
FOR locName IN ([Germany], [Kenya])
) As AirTransfers
) AirT on AirT.productID = p.ProductID
LEFT JOIN (
SELECT productID, [Germany] AS [Road Transfer - Germany], [Kenya] AS [Road Transfer - Kenya]
FROM (select productID, l.locName, qty
FROM sales s
INNER JOIN Locations l on l.locID = s.locID
where transfer = 'Road Transfer') as SourceTable
PIVOT (SUM(qty)
FOR locName IN ([Germany], [Kenya])
) As RoadTransfers
) RoadT on RoadT.productID = p.ProductID
Good morning,
I have been trying to get my mind around doing a simple count of records in an application I am making in visual studio.
The database associated with the application keeps records of people each of them belonging in a certain department. Within the application I want to create a statistics window which counts how many people of each department are currently kept in the database.
In my mind the way to do this would be to select distint values from the department column and then for each result to query again with the count method in order to get a value for each, however I feel this is not the quite correct way to do so.
What I want pretty much is to have a window with a grid view in which the first column holds the name of the department and the second one holds the number of people in that very same department but due to actually beeing new to visual studio and programming in general I couldn't quite figure out how to do this.
Any help would be appreciated.
you can do it by simple join query in database . try following query :
SELECT A.ID , SUM(CASE WHEN B.ID IS NOT NULL THEN 1 ELSE 0 END) AS TOTALNOOFPEOPLE
FROM DEPARTMENT AS A LEFT OUTER JOIN PEOPLE AS B ON A.ID = B.DEPARTMENTID
GROUP BY A.ID
CREATE TABLE [dbo].[Dept]([DeptName] varchar NULL,
[StudName] varchar NULL)
select DeptName,count(*) as NoOfPeople from [sample].[dbo].[Dept] group by [DeptName]
In windows form
SqlDataAdapter sda=new SqlDataAdapter ('select DeptName,count(*) as NoOfPeople from [sample].[dbo].[Dept] group by [DeptName]',con)
DataTable dt=new DataTable();
sda.fill(dt);
dataGridView1.DataSourc=dt;
dataGridView1.DataBind();
I have the requirement to build a asp.net sign up form which will allow students to register a training. So far I built a database in sql server and 3 tables: student, training & studenttraining
My question is, how can I limit the form from displaying the dates available once a particular training gets full, or meabe how can I prevent by checking the tables that the user can register?
Select count(*) as SeatsFilled, t.TrainingKey, t.TrainingDate
From Training t
Inner Join StudentTraining st on t.TrainingKey = st.TrainingKey
Group By t.TrainingKey, t.TrainingDate
Having count(*) < t.TotalSeats
TotalSeats is a column in the Training table that specifies how many seats the training provides. I assumed StudentTraining is a many-to-many bridge table between Students and Training.
You'll need to establish what "full" is first. Then, you can do a simple
SELECT COUNT(id) FROM table to determine if the full amount is already reached.
I guess you could have a MaxTraining column in the training table and when you get the data for your form, you can count the training entries in studenttraining, and if it equals MaxTraining, then don't bring that training entry, cause it means it's already full.