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
Related
In Attendance Management system user login and just can mark
attendance or apply for leave and record save in database.there is no
option for absent.how can i show absent in gridview on the day when he
do not mark attendance.in below records adil is absent 6 days but how can i show in asp.net that he was absent 6 days along with date?
attId Name Attndancestatus Date Username
1 ADIL presnet 14/10/10
2 Adil present 20/10/10
Assuming you have 3 tables:
ListOfDatesToMarkAttendance: Have all avaiable dates to mark attendence
ListOfUsersToMarkAttendancePerDate: Have all avaiable users to mark attendence, on each date
Attendance: Regist Attndancestatus (absent rows are missing)
Once we do not know the DB schema, you can do something like that:
select d.date, u.name,
Attndancestatus = isnull(s.Attndancestatus,'absent')
--when?
from ListOfDatesToMarkAttendance d
--who?
join ListOfUsersToMarkAttendancePerDate u on
[relate columns here]
--Attendance status
left join Attendance s on
[relate with ListOfDatesToMarkAttendance and ListOfUsersToMarkAttendancePerDate here]
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.
Am using datalist for one of my scenario. Datalist Items are: Name and Email. These things are binding from database. So far so good.
Concept:
User will register their name and email id in registration form. Once registration completed, data will store into table(registration). Also user need to verify their email id. Verified email will store into other table(verified) in my database.
What I want is:
I need to display the verified items only at first. After that unverified items should display in my datalist.
What I tried is:
I used DataList Itemdatabound. where i can do color difference between verified and unverified items. But I fail to display the verified records at first.
My query as follows ,
Select Distinct t1.name from Registration as t1
inner join Verification as t2 on t1.Email=t2.Email
and t2.status='Success'
Try below code. ORDER BY T2.Status DESC clause here will ensure that those records which exists both in Registration and Verification tables will be retrieved in first place. For more info on ORDER BY see here: https://msdn.microsoft.com/en-us/library/ms188385.aspx
SELECT name, T1.Email
FROM Registration T1
LEFT JOIN Verification T2
ON T1.Email = T2.Email
ORDER BY T2.status DESC, T1.name ASC
Try this: (I've edited my answer to avoid the error on order by and distinct)
SELECT name, status
FROM (
SELECT Distinct t1.name as name, t2.status as status
FROM Registration as t1
LEFT JOIN Verification as t2 ON t1.Email=t2.Email
) InnerSelect
ORDER BY CASE WHEN status='Success' THEN 0 ELSE 1 END, -- This is the 'trick'...
name
I have some data within a table I am importing into an ERP solution. The data is presented like this:
buyer name,order id,shipment item id,sku,quantity shipped, price etc
The shipment item ID is a unique value and is the primary key along with the order id.
My problem is this:
I need to locate each distinct order and create a sales order based upon that information.
The issue I am having is:
Each shipment item ID has its own row within the database and a simple
while(reader.read()){
...logic here...
}
will not work as it will attempt to create n amount of sales orders for the same customer.
I need to formate a query that will take each shipment item ID and put its SKU, quantity etc into one row so I can attach it properly but I am unsure how this would work.
Any help would be much appreciated.
You need to use a group by clause to deduplicate the rows to get the top level information
SELECT [buyer name], [order id], etc
FROM orderTable
GROUP BY [buyer name], [order id], etc
WHERE [order id] = 1
then select all the rows seperately
SELECT *
FROM orderTable
WHERE [order id] = 1
I have found a solution with the ERP software provider which will allow me to use a basic SQL statement and do an update on the any sales order which has a primary key of the order ID. This will allow each corresponding shipment item id to be added to the sales order without having to do extra SQL "massaging" as if the record exists it will update it, otherwise it will create a new one.
Thanks everyone for your suggestions.
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.