find consecutive value in SQL -
i want find out consecutive absences each student each module, here original result.

and want output add consecutive absences column , find out consecutive absent each student module.

try this.
declare @tbl table ( [id] [int] identity(1,1), [studentcode] varchar(50), [semester] varchar(50), [modulecode] varchar(50), [date] varchar(50), [wkno] varchar(50), [attended] varchar(50), [absent] [int] ) insert @tbl select [studentcode] ,[semester] ,[modulecode] ,[date] ,[wkno] ,[attended] ,[absent] attendance order studentcode,modulecode,date select t1.*, case when (t1.absent = 1 , t2.absent = 1) , (t1.modulecode = t2.modulecode) 1 else 0 end cosecutiveabsence @tbl t1 left outer join @tbl t2 on t1.id = t2.id + 1
Comments
Post a Comment