CREATE TABLE #temp1( [cStudentId] [char](9) NOT NULL, [iSchoolCode] [int] NOT NULL, [dtEnrollmentDate] [datetime] NOT NULL, [cGradeCode] [char](2) NOT NULL, [cAbsenceCode] [char](1) NOT NULL, [vcAbsenceType] [varchar](20) NOT NULL, [iSchoolDayCategoryCode] [int] NOT NULL, [dtEntryDate] [datetime] NOT NULL) insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-01')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-02')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Excused',8,'2012-10-03')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-04')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-05')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-06')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-07')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Excused',8,'2012-10-08')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Excused',8,'2012-10-09')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Excused',8,'2012-10-10')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-11')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-12')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-13')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-14')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Excused',8,'2012-10-15')insert into #temp1 values ('003491714',469,'2012-10-08','12','E','Present',8,'2012-10-16')
cStudentId iSchoolCode dtEnrollmentDate cGradeCode cAbsenceCode vcAbsenceType iSchoolDayCategoryCode dtEntryDate003491714 469 2012-10-08 00:00:00.000 12 E Present 8 2012-10-05 00:00:00.000003491714 469 2012-10-08 00:00:00.000 12 E Excused 8 2012-10-10 00:00:00.000003491714 469 2012-10-08 00:00:00.000 12 E Excused 8 2012-10-15 00:00:00.000
SELECT *FROM (SELECT ROW_NUMBER() OVER(PARTITION BY x.cStudentId,x.dtEnrollmentDate ORDER BY dtEnrollmentDate asc ) AS DSeq,x.*FROM #temp1 x) tempWHERE DSeq not in (5,10,15)
DELETE tempFROM (SELECT ROW_NUMBER() OVER(PARTITION BY x.cStudentId,x.dtEnrollmentDate ORDER BY dtEnrollmentDate asc ) AS DSeq,x.*FROM #temp1 x) tempWHERE DSeq not in (5,10,15)
DELETE tempFROM ( SELECT ROW_NUMBER() OVER(PARTITION BY x.cStudentId,x.dtEnrollmentDate ORDER BY dtEnrollmentDate asc ) AS DSeq, x.* FROM #temp1 x ) tempWHERE ( DSeq % 5 ) > 0