find consecutive value in SQL -


i want find out consecutive absences each student each module, here original result.

enter image description here

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

enter image description here

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

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -