| Author |
Topic |
|
shm
Yak Posting Veteran
86 Posts |
Posted - 2009-01-06 : 00:41:46
|
| hi i have written sp ,in the sp query am taking the emp detail for the daterange fromdate and todate...wt am trying to get is if the emp is not present in that daterange he should also come..means total 5 employee ,3 employees are present in the date between '01-02-2008' and '03-03-2008' but 2 are absent..how can i get the data for the absentee also along with other 3 employee..i shld display date as null to the absentee...i tried using union but it is coming wrong.. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-06 : 00:56:00
|
| select empid,cast(null as datetime) as date into #temp from urtable where empdate not between @prevdate and @nowdate insert into #tempselect empid,empdate as date from urtable where empdate between @prevdate and @nowdateselect * from #temp |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-06 : 01:21:41
|
| Something likeselect emp.employeename, att.date from employee_master as empleft join attendance as att on emp.emp_code=att.emp_codeand att.date between @date1 and @date2MadhivananFailing to plan is Planning to fail |
 |
|
|
shm
Yak Posting Veteran
86 Posts |
Posted - 2009-01-06 : 01:27:04
|
| ok SELECT SEPG_EMP.EMP_NAME, HRMS_SB.SBD_ITEM_DESC , PLT.DATE, P.PRJ_PROJECT_NAME, PH.PPH_PHASE_NAME, PM.PMO_MOD_NAME, PT.PTK_TASK_NAME, PB.PBG_ID, PB.PBG_DESCRIPTION, SD.SDLC_ITEM_NAME, SA.SUB_ITEM_NAME, PLT.PLT_HRS, PLT.PLT_DETAILS FROM PROJECT_LOG_TIME PLT INNER JOIN EMPLOYEE SEPG_EMP ON SEPG_EMP.EMP_SEQ_NO = PLT.EMP_SEQ_NO INNER JOIN PROJECT_TASK PT ON PT.PTK_SEQ_NO = PLT.PLT_OBJECT INNER JOIN PROJECT_MODULE PM ON PM.PMO_MOD_SEQ_NO = PT.PMO_MOD_SEQ_NO INNER JOIN PROJECT_PHASE PH ON PH.PPH_SEQ_NO = PM.PPH_SEQ_NO INNER JOIN PROJECT P ON P.PRJ_SEQ_NO = PH.PRJ_SEQ_NO INNER JOIN SYS_BUSINESS_CODE_DETAIL AS SB ON SB.SBD_ITEM_CODE = P.PRJ_STATUS_ITEM_CODE and SB.SBD_ITEM_DESC='In Progress' LEFT OUTER JOIN PROJECT_BUG PB ON PB.PBG_ID = PLT.PBG_ID INNER JOIN SUB_ACTIVITY SA ON SA.SUB_ITEM_CODE = PLT.PLT_ACT_TYPE_CODE INNER JOIN SDLC_ACTIVITY SD ON SD.SDLC_ITEM_CODE = PLT.PLT_ACT_HEAD_ITEM_CODE INNER JOIN [10.10.210.2].hrms.dbo.EMPLOYEE HRMS_EMP ON HRMS_EMP.EMP_LOG_ID = SEPG_EMP.EMP_SAMS_ID INNER JOIN [10.10.210.2].hrms.dbo.SYS_BUSINESS_CODE_DETAIL HRMS_SB ON HRMS_SB.SBD_ITEM_CODE = HRMS_EMP.EMP_DESIG_ITEM_CODE WHERE HRMS_EMP.EMP_SEQ_NO = 525 AND HRMS_EMP.EMP_DESIG_ITEM_CODE = 182 ---AND date between'01-02-2008' AND '03-03-2008' wihout giving the date the data is belowemp dateram 2008-01-03 ram 2008-01-08 ram 2008-01-09 prasad 2008-01-17 prasad 2008-02-04prasad 2008-02-06 prasad 2008-02-07 prasad 2008-02-11 geeta 2008-03-14 geeta 2008-03-10 geeta 2008-04-02 geeta 2008-03-19 geeta 2008-05-23 if i give the date range then the geeta will not display as there is no record for the date range date between'01-02-2008' AND '03-03-2008' ..i want that to display as the date as null for the geeta record...i think the above explanation can understand wt am trying to get.... |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-06 : 01:48:24
|
| use case ,try like thisselect empid, case when empdate >'01-02-2008' and empdate < '03-03-2008' then null else empdate end as date from urtable |
 |
|
|
shm
Yak Posting Veteran
86 Posts |
Posted - 2009-01-06 : 02:31:18
|
| hi no am not getting correct..i want all the rows along with geetha employee and date as null for that. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-06 : 02:50:49
|
| get that data into temptable and use this codedeclare @temp table(emp varchar(32), date datetime)insert into @temp select 'ram', '2008-01-03' union allselect 'ram', '2008-01-08' union allselect 'ram', '2008-01-09' union allselect 'prasad', '2008-01-17' union allselect 'prasad', '2008-02-04' union allselect 'prasad', '2008-02-06 ' union allselect 'prasad', '2008-02-07 ' union allselect 'prasad', '2008-02-11' union allselect 'geeta', '2008-03-14' union allselect 'geeta','2008-03-10' union allselect 'geeta', '2008-04-02' union allselect 'geeta', '2008-03-19' union allselect 'geeta' ,'2008-05-23'select emp, case when date >= '01-02-2008' AND date <= '03-03-2008' then date else null end as date from @temp |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-06 : 02:55:03
|
something like thisSELECT SEPG_EMP.EMP_NAME,HRMS_SB.SBD_ITEM_DESC ,PLT.DATE,P.PRJ_PROJECT_NAME, PH.PPH_PHASE_NAME, PM.PMO_MOD_NAME, PT.PTK_TASK_NAME, PB.PBG_ID, PB.PBG_DESCRIPTION, SD.SDLC_ITEM_NAME, SA.SUB_ITEM_NAME, PLT.PLT_HRS, PLT.PLT_DETAILSFROM EMPLOYEE SEPG_EMPLEFT JOIN PROJECT_LOG_TIME PLT ON SEPG_EMP.EMP_SEQ_NO = PLT.EMP_SEQ_NOLEFT JOIN PROJECT_TASK PT ON PT.PTK_SEQ_NO = PLT.PLT_OBJECTAND PLT.date between'01-02-2008' AND '03-03-2008'LEFT JOIN PROJECT_MODULE PM ON PM.PMO_MOD_SEQ_NO = PT.PMO_MOD_SEQ_NO LEFT JOIN PROJECT_PHASE PH ON PH.PPH_SEQ_NO = PM.PPH_SEQ_NOLEFT JOIN PROJECT P ON P.PRJ_SEQ_NO = PH.PRJ_SEQ_NO LEFT JOIN SYS_BUSINESS_CODE_DETAIL AS SB ON SB.SBD_ITEM_CODE = P.PRJ_STATUS_ITEM_CODE and SB.SBD_ITEM_DESC='In Progress'LEFT OUTER JOIN PROJECT_BUG PB ON PB.PBG_ID = PLT.PBG_ID LEFT JOIN SUB_ACTIVITY SA ON SA.SUB_ITEM_CODE = PLT.PLT_ACT_TYPE_CODE LEFT JOIN SDLC_ACTIVITY SD ON SD.SDLC_ITEM_CODE = PLT.PLT_ACT_HEAD_ITEM_CODELEFT JOIN [10.10.210.2].hrms.dbo.EMPLOYEE HRMS_EMP ON HRMS_EMP.EMP_LOG_ID = SEPG_EMP.EMP_SAMS_IDAND HRMS_EMP.EMP_SEQ_NO = 525 AND HRMS_EMP.EMP_DESIG_ITEM_CODE = 182 INNER JOIN [10.10.210.2].hrms.dbo.SYS_BUSINESS_CODE_DETAIL HRMS_SB ON HRMS_SB.SBD_ITEM_CODE = HRMS_EMP.EMP_DESIG_ITEM_CODE |
 |
|
|
shm
Yak Posting Veteran
86 Posts |
Posted - 2009-01-06 : 04:06:11
|
| hi visakhit is working fine i made small change to that then i got wt i was expected the resultthank u so much... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-06 : 08:44:42
|
welcome |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
shm
Yak Posting Veteran
86 Posts |
Posted - 2009-01-07 : 00:46:05
|
| hi thank u for that link... |
 |
|
|
|