Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to make attendance system which is format on monthly base.
1 2 3 S 5 6 7 ---MONTH DATE
P P A S P P P --- ATTENDANCE STATUS

I want to print S(sunday) instead of 4 .
Posted
Updated 28-Dec-15 21:23pm
v2
Comments
Maciej Los 29-Dec-15 3:39am    
Could you be so kind and provide more details about yor issue. What have you tried? Where are you stuck?
Member 12233583 29-Dec-15 4:10am    
I am using View and store procedure in sql server 2008 R2

My View is::


ALTER view [dbo].[vwAttandenceDetails]
as
select sd.id, sd.name, att.attendance_status,sd.rf_code,
DATEPART(day,att.attendance_date) as 'day_Name'
from tb_student_detail as sd
left join tb_attendance as att
on att.student_id=sd.id


And Stored procedure is
ALTER proc [dbo].[disp_monthly_report]
as
select rf_code as 'Student ID', name as 'Name',
isnull([1],'A') as '1',
isnull([2],'A') as '2',
isnull([3],'A') as '3',
isnull([4],'A') as '4',
isnull([5],'A') as '5',
isnull([6],'A') as '6',
isnull([7],'A') as '7',
isnull([8],'A') as '8',
isnull([9],'A') as '9',
isnull([10],'A') as '10',
isnull([11],'A') as '11',
isnull([12],'A') as '12',
isnull([13],'A') as '13',
isnull([14],'A') as '14',
isnull([15],'A') as '15',
isnull([16],'A') as '16',
isnull([17],'A') as '17',
isnull([18],'A') as '18',
isnull([19],'A') as '19',
isnull([20],'A') as '20',
isnull([21],'A') as '21',
isnull([22],'A') as '22',
isnull([23],'A') as '23',
isnull([24],'A') as '24',
isnull([25],'A') as '25',
isnull([26],'A') as '26',
isnull([27],'A') as '27',
isnull([28],'A') as '28',
isnull([29],'A') as '29',
isnull([30],'A') as '30',
isnull([31],'A') as '31',

(select count(id) from vwAttandenceDetails where id=pio.id and attendance_status='P') as 'P'
from vwAttandenceDetails
pivot
(
max(attendance_status)
for day_name
in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],
[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31])
)as pio


I want to know which date is sunday(each sunday of month) and print that column as "S".

This is attendance management system
Tomas Takac 29-Dec-15 13:45pm    
Do not post code in comments. You are supposed to update your question via the Improve question link.

Stick a modified version of this in your function.
SELECT CASE DATEPART(WEEKDAY,att.Attendance_Date)
WHEN 1
THEN 'S'
ELSE
DATEPART(DAY,GETDATE())
END AS Day_Name
 
Share this answer
 
Comments
Member 12233583 30-Dec-15 2:27am    
Dear Sir/Madam

Your code is very helpful to me but it need some more correction for me.

The date which has Sunday it give error like...


SELECT CASE DATEPART(WEEKDAY,'2015-12-27 00:00:00.000')
WHEN 1
THEN 'S'
ELSE
DATEPART(DAY,GETDATE())
END AS Day_Name

Conversion failed when converting the varchar value 'S' to data type int.
Thanks for replying..

But i stuck at another place that is

how to generate dynamic column using pivot function in sql server 2008 R2.
means i have to generate 31 column for january month and 28 or 29 column for feburary month(as per days in months).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900