| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-10-27 : 08:47:09
|
| shabir writes "i have sql query likeselect * from table where emp_code='"&emp&"' and day(dte)>='"&beginday&"' and day(dte)<='"&endday&"'"this is retrieving correct result but while displaying datai am not able to associte the date field with each emp_codelikeemp_code istday endday 3rdday....... till end of month10000000 present present Absent10000002 Absent present Absent10000003 Absent present AbsentRemember there can be some times no record for emp_code,any way it should retrieve data like above i have shouwn" |
|
|
tuenty
Constraint Violating Yak Guru
278 Posts |
Posted - 2004-10-27 : 17:21:50
|
| if your table is something like tblAssistance(empCode,wordDay,assistance) then you would need to make a cross table Another thing you shouldn't discriminate by the day (day(WorkDay) between day(@beginDate) and day(@endDate)) discriminate by the whole date instead and display in one column month and year,and the days you want to show in different columns you can use a view or a stored procedurebut I think you can easily create this kind of reports with Crystal Reports*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*A candle loses nothing by lighting another candle |
 |
|
|
tuenty
Constraint Violating Yak Guru
278 Posts |
Posted - 2004-10-28 : 11:18:14
|
| [code]Declare @Assistance Table ( empID char(10), workDay datetime, assistance bit)Insert into @AssistanceSelect 10000000, '10/1/2004', 1 UnionSelect 10000000, '10/2/2004', 0 UnionSelect 10000000, '10/3/2004', 0 UnionSelect 10000000, '10/4/2004', 1 UnionSelect 10000000, '10/5/2004', 0 UnionSelect 10000000, '10/6/2004', 1 UnionSelect 10000000, '10/7/2004', 1 UnionSelect 10000000, '10/8/2004', 1 UnionSelect 10000000, '10/9/2004', 1 UnionSelect 10000000, '10/10/2004', 0 UnionSelect 10000002, '10/1/2004', 0 UnionSelect 10000002, '10/2/2004', 0 UnionSelect 10000002, '10/3/2004', 0 UnionSelect 10000002, '10/4/2004', 1 UnionSelect 10000002, '10/5/2004', 0 UnionSelect 10000002, '10/6/2004', 1 UnionSelect 10000002, '10/7/2004', 0 UnionSelect 10000002, '10/8/2004', 1 UnionSelect 10000002, '10/9/2004', 1 UnionSelect 10000002, '10/10/2004', 1 UnionSelect 10000003, '10/1/2004', 0 UnionSelect 10000003, '10/2/2004', 0 UnionSelect 10000003, '10/3/2004', 0 UnionSelect 10000003, '10/4/2004', 1 UnionSelect 10000003, '10/5/2004', 0 UnionSelect 10000003, '10/6/2004', 0 UnionSelect 10000003, '10/7/2004', 0 UnionSelect 10000003, '10/8/2004', 1 UnionSelect 10000003, '10/9/2004', 1 UnionSelect 10000003, '10/10/2004', 1Select empID, max(right(convert(char (11),workday,106),8)) as AssistanceMonth, max(case datepart(day,workday) When 1 then case assistance When 1 then 'Present' else 'Absent' end else '' end) as day1, max(case datepart(day,workday) When 2 then case assistance When 1 then 'Present' else 'Absent' end else '' end) as day2, max(case datepart(day,workday) When 3 then case assistance When 1 then 'Present' else 'Absent' end else '' end) as day3...from @Assistancegroup by empID[/code]Results[code]empID AssistanceMonth day1 day2 day3 ...---------- --------------- ------- ------- ------- ...10000000 Oct 2004 Present Absent Absent ...10000002 Oct 2004 Absent Absent Absent ...10000003 Oct 2004 Absent Absent Absent ...[/code]To determine the amount of working dateshttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=40692*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*A candle loses nothing by lighting another candle |
 |
|
|
|
|
|