Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ggardei
Starting Member
6 Posts |
Posted - 2010-04-05 : 14:00:46
|
| Greetings all.I have the table that contains attendance status for students in our elementary grades. Due to an error in my coding the attendance entry page runs the add record script instead of an update script; resulting in multiple attendance entries for the date.ACA_ElmAttendanceData StudentID Status Date Comment1234, Late, 01/01/20101234, Late, 01/02/20101234, Present, 01/03/20101234, Left Early, 01/03/2010I need to generate a report showing the dates that a student has multiple entries for the same day.ThanksGeorgeGeorge W. GardeiGod's Bible School & College(513) 763-65161810 Young StreetCincinnati, OH. 45202 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-05 : 14:25:48
|
| [code]-- List a count of records for each StudentID/Date, Where the count > 1. SELECT StudentID, Date, COUNT(*) AS RecordCountFROM ACA_ElmAttendanceDataGROUP BY StudentID, DateHAVING COUNT(*) > 1-- List all records counted in the above querySELECT a.StudentID, a.Status, a.Date, a.CommentFROM ACA_ElmAttendanceData aINNER JOIN ( SELECT StudentID, Date FROM ACA_ElmAttendanceData GROUP BY StudentID, Date HAVING COUNT(*) > 1 ) e ON a.StudentID = e.StudentID AND a.Date = e.DateThere are 10 types of people in the world, those that understand binary, and those that don't.[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-05 : 23:59:22
|
| [code]SELECT StudentID,Status,Date,CommentFROM(SELECT StudentID,Status,Date,Comment,COUNT(StudentID) OVER (PARTITION BY Date) AS CntFROM Table)tWHERE Cnt > 1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|