
Alter procedure GenerateAttendance
@Month as int,
@Year as int
as

Declare @i as integer 
DECLARE @SQLString nvarchar(max); 
select @i=1

while (@i<=31)
begin
select @i

--select @SQLString =N'select a.month
--,a.[AdmissionNo],a.d' + cast(@i as varchar) +',e.d' + cast(@i as varchar) +'
--from attdata a
--join StudentMaster b on b.AdmissionNo=a.[AdmissionNo]
--join studentsection c on c.StudentName=b.Oid
--join AcademicYearMaster d on d.Oid=c.AcademicYearId
--join AttendanceRegisterDet e on e.StudentName=c.Oid
--join AttendanceRegisterMast f on f.Oid=e.MasterID
--where a.d' + cast(@i as varchar) +'=''A''
--and d.startyear=2017
--and f.month=6'

select @SQLString =N'update AttendanceRegisterDet set d' + cast(@i as varchar) 
+ ' =6'
+ ' from attdata a
join StudentMaster b on b.AdmissionNo=a.[AdmNo]
join studentsection c on c.StudentName=b.Oid
join AcademicYearMaster d on d.Oid=c.AcademicYearId
join AttendanceRegisterDet e on e.StudentName=c.Oid
join AttendanceRegisterMast f on f.Oid=e.MasterID
where a.d' + cast(@i as varchar) +'=''A''
and d.startyear=' + cast(@Year as varchar)
+ ' and a.month=f.Month 
and f.month=' + cast(@Month as varchar) 



--select @SQLString
exec sp_executesql  @SQLString
select @i=@i+1
end


go


Exec GenerateAttendance 12,2017