visual studio 2008 - to count the no of days present and absent -
i have stored employee's attendance following.....
columns : employeecode day1 day2 day3 ................ day31 values : ec001 p p
for purpose need present day count & absent day count every employee. how it?
hi copy , paste code , work fine. check if change table name have in database. please don't forget vote if helps. thank you!
declare @tablename varchar(100) declare @tablefieldid varchar(100) set @tablename = 'tbl_attendance' set @tablefieldid = 'employeecode' ------------- no need edit here ----------------------- declare @sql nvarchar(max) declare @present nvarchar(max) declare @absent nvarchar(max) set @sql = 'select ' + @tablefieldid + '' set @present = '' set @absent = '' select @present = @present + ' case when ' + syscolumns.[name] + ' = ''p'' 1 else 0 end + ' + char(10) + char(13), @absent = @absent + ' case when ' + syscolumns.[name] + ' = ''a'' 1 else 0 end + ' + char(10) + char(13) sysobjects inner join syscolumns on sysobjects.id = syscolumns.id sysobjects.[name] = @tablename -- remove last + set @present = left( @present, len(@present) - 4) + char(10) + char(13) set @absent= left( @absent, len(@absent) - 4) + char(10) + char(13) set @sql = @sql + ', present =' + @present + ', absent =' + @absent + 'from ' + @tablename + char(10) + char(13) exec sp_executesql @sql
Comments
Post a Comment