Rohit SQL Note

download Rohit SQL Note

If you can't read please download the document

Transcript of Rohit SQL Note

Select DISTINCT --Wf.Notification_Id, -- Psth.Creator_Person_Id, -- haou.organization_id, pap.employee_number, Pap.First_Name Employee_Name, -- Haou.Name Department_Name, --NULL section, :p_category category,-- NVL(:p_type,-- (SELECT name-- FROM per_absence_attendance_types-- WHERE absence_attendance_type_id = pssh.information5-- )) type,-- To_Char(To_Date(Decode(Pssh.Information9,'CONFIRMED',Pssh.Information1,'PLANNED',Pssh.Information3),'rrrr-mm-dd'),'dd-Mon-RRRR') Date_From,-- To_Char(To_Date(Decode(Pssh.Information9,'CONFIRMED',Pssh.Information2,'PLANNED',Pssh.Information4),'rrrr-mm-dd'),'dd-Mon-RRRR') Date_To, -- to_date(DECODE(pssh.information9,'CONFIRMED',pssh.information2,'PLANNED',pssh.information4),'YYYY-MM-DD')-to_date(DECODE(pssh.information9,'CONFIRMED',pssh.information1,'PLANNED',pssh.information3),'YYYY-MM-DD')+1 duration, TRUNC(psth.creation_date) Submission_Date, --wf.l_date action_date, wf.l_action status, Decode(Wf.L_Action,'Approve',Null,Wf.L_Role) Pending_With, --Decode(Wf.L_Action,'Approve',Null,Wf.L_Role_Num) Action_With_Num, -- CASE-- WHEN wf.l_action = 'Pending'-- THEN TRUNC(tot_secs/84600)-- ||' Day(s), '-- ||TRUNC(mod(tot_secs,84600)/3600)-- ||' Hour(s), '-- ||TRUNC(mod(mod(tot_secs,84600),3600)/60)-- ||' Min(s)'-- ELSE NULL-- END pending_duration,--CASE-- WHEN lower(:p_category) = 'leave'-- THEN ''-- WHEN lower(:p_category) != 'leave'-- THEN-- Case-- WHEN :p_category like '%LEAVE%'-- THEN-- (SELECT 'Request For - '-- ||segment1-- ||', Type - '-- ||segment2-- ||', Leave Due Date - '-- ||TO_CHAR(to_date(segment3,'yyyy/MM/DD HH24:MI:SS'),'DD-Mon-RRRR')-- ||', Remarks - '-- ||segment4-- FROM per_analysis_criteria-- WHERE analysis_criteria_id =-- (SELECT value-- FROM pqh_ss_value_history-- WHERE name = 'P_ANALYSIS_CRITERIA_ID'-- AND step_history_id =pssh.step_history_id-- )-- ) WHEN :p_category = 'ESC Letter Request' Then (SELECT 'Purpose - ' ||segment1 ||', Addresee - ' ||segment2 ||Nvl2(Segment3,', Remarks - '||Segment3,'') ||nvl2(segment4,', Bank Name - '||segment4,'') From Per_Analysis_Criteria -- Where ID_FLEX_NUM= 50381 where analysis_criteria_id = --548 ( SELECT value FROM pqh_ss_value_history pssvh1 Where pssvh1.Name = 'P_ANALYSIS_CRITERIA_ID' -- AND step_history_id = pssvh.step_history_id (select max(step_history_id) from pqh_ss_value_history pssvh2 where pssvh1.step_history_id = pssvh2.step_history_id and pssvh2.Name = 'P_ANALYSIS_CRITERIA_ID' ) ) )-- WHEN :p_category LIKE '%REQUEST%'-- THEN-- (SELECT segment1-- ||' - '-- ||NVL(segment6,0)-- ||' No(s), '-- ||nvl2(segment2,segment2-- ||' - '-- ||NVL(segment7,0)-- ||' No(s), ','')-- ||nvl2(segment3,segment3-- ||' - '-- ||NVL(segment8,0)-- ||' No(s), ','')-- ||nvl2(segment9,segment9-- ||' - '-- ||NVL(segment10,0)-- ||' No(s), ','')-- ||nvl2(segment4,'Reason - '-- ||segment4-- ||', ','')-- ||nvl2(segment5,'Remarks - '-- ||segment5,'')-- FROM per_analysis_criteria-- WHERE analysis_criteria_id =-- (SELECT value-- FROM pqh_ss_value_history-- WHERE name = 'P_ANALYSIS_CRITERIA_ID'-- AND step_history_id =pssh.step_history_id-- )-- )-- WHEN :p_category = ''-- THEN-- (SELECT 'Reason - '-- ||segment1-- ||nvl2(segment2,', Remarks - '-- ||segment2,'')-- ||', Date of Release - '-- ||TO_CHAR(to_date(segment3,'yyyy/MM/DD HH24:MI:SS'),'DD-Mon-RRRR')-- ||', Date of Return - '-- ||TO_CHAR(to_date(segment4,'yyyy/MM/DD HH24:MI:SS'),'DD-Mon-RRRR')-- FROM per_analysis_criteria-- WHERE analysis_criteria_id =-- -- -- -- (SELECT value-- FROM pqh_ss_value_history-- WHERE name = 'P_ANALYSIS_CRITERIA_ID'-- AND step_history_id =pssh.step_history_id-- )-- )-- WHEN :p_category = ''-- THEN-- (SELECT 'Date of Leaving - '-- ||TO_CHAR(to_date(segment1,'yyyy/MM/DD HH24:MI:SS'),'DD-Mon-RRRR')-- ||', Reason - '-- ||segment2-- ||nvl2(segment3,', Remarks - '-- ||segment3,'')-- FROM per_analysis_criteria-- WHERE analysis_criteria_id =-- (SELECT value-- FROM pqh_ss_value_history-- WHERE name = 'P_ANALYSIS_CRITERIA_ID'-- AND step_history_id =pssh.step_history_id-- )-- )-- WHEN :p_category = ''-- THEN-- (SELECT 'Type - '-- ||segment1-- ||', Description - '-- ||segment2-- ||', Reason - '-- ||segment3-- ||', Needed Date - '-- ||TO_CHAR(to_date(segment4,'yyyy/MM/DD HH24:MI:SS'),'DD-Mon-RRRR')-- FROM per_analysis_criteria-- WHERE analysis_criteria_id =-- (SELECT Value-- FROM pqh_ss_value_history pssh-- WHERE Name = 'P_ANALYSIS_CRITERIA_ID'-- AND Step_History_Id = Pssh.Step_History_Id-- )-- ) End Request_DetailsFROM pqh_ss_step_history pssh, pqh_ss_transaction_history psth, pqh_ss_value_history psvh, per_all_people_f pap, per_all_assignments_f paa, hr_all_organization_units haou, (SELECT DISTINCT wn.notification_id l_notification_id, wf_directory.getroledisplayname ( NVL (wn.more_info_role, wn.recipient_role) ) l_role, Nvl(Wn.More_Info_Role, Wn.Recipient_Role) L_Role_Num, -- (NVL(wn.end_date,sysdate)-wn.begin_date)*86400 tot_secs, DECODE ( l.lookup_code, 'SFL', (hr_general.decode_lookup ('PQH_SS_APPROVAL_STATUS', 'PENDING')), DECODE ( wn.status, 'CANCELED', (hr_general.decode_lookup ('PQH_SS_APPROVAL_STATUS', 'BEATEN')), l.meaning ) ) l_action, na.text_value l_comments, ias.end_date l_date, i.item_type, i.item_key, wn.notification_id FROM wf_activities a, wf_notification_attributes na, wf_process_activities pa, wf_items i, wf_item_activity_statuses ias, wf_lookups_tl l, wf_user_roles wur, wf_notifications wn WHERE ias.item_type = i.item_type AND ias.item_key = i.item_key AND ias.notification_id IS NOT NULL AND wn.notification_id = na.notification_id(+) AND na.name(+) = 'WF_NOTE' AND NVL (ias.activity_result_code, 'A') NOT IN ('SFL', 'RESUBMIT') AND ias.process_activity = pa.instance_id AND pa.activity_name = a.name AND pa.activity_item_type = a.item_type AND a.result_type NOT IN ('*', 'HR_DONE') AND i.item_type ='HRSSA' AND i.begin_date BETWEEN a.begin_date AND NVL (a.end_date, i.begin_date) AND a.result_type = l.lookup_type AND NVL (ias.activity_result_code, 'SFL') = l.lookup_code AND l.language = 'US' And Ias.Assigned_User = Wur.Role_Name AND Ias.Notification_Id = Wn.Group_Id Union SELECT DISTINCT wn.notification_id l_notification_id, wf_directory.getroledisplayname (wn.recipient_role) l_role, Nvl(Wn.More_Info_Role, Wn.Recipient_Role) L_Role_Num, -- (NVL(wn.end_date,sysdate)-wn.begin_date)*86400 tot_secs, DECODE ( l.lookup_code, 'SFL', (hr_general.decode_lookup ('PQH_SS_APPROVAL_STATUS', 'PENDING')), DECODE ( wn.status, 'CANCELED', (hr_general.decode_lookup ('PQH_SS_APPROVAL_STATUS', 'BEATEN')), l.meaning ) ) l_action, na.text_value l_comments, ias.end_date l_date, i.item_type, i.item_key, wn.notification_id FROM wf_activities a, wf_notification_attributes na, wf_process_activities pa, wf_items i, wf_item_activity_statuses_h ias, wf_lookups_tl l, wf_user_roles wur, wf_notifications wn WHERE ias.item_type = i.item_type And Ias.Item_Key = I.Item_Key AND ias.notification_id IS NOT NULL AND wn.notification_id = na.notification_id(+) AND na.name(+) = 'WF_NOTE' AND NVL (ias.activity_result_code, 'A') NOT IN ('SFL', 'RESUBMIT') AND ias.process_activity = pa.instance_id AND pa.activity_name = a.name AND pa.activity_item_type = a.item_type AND a.result_type NOT IN ('*', 'HR_DONE') AND i.item_type ='HRSSA' AND i.begin_date BETWEEN a.begin_date AND NVL (a.end_date, i.begin_date) AND a.result_type = l.lookup_type AND NVL (Ias.Activity_Result_Code, 'SFL') = L.Lookup_Code AND l.language = 'US' AND ias.assigned_user = wur.role_name And Ias.Notification_Id = Wn.Group_Id ) wfWHERE pap.person_id = psth.selected_person_idAND pap.person_id = paa.person_idAND haou.organization_id = paa.organization_idAND TRUNC(sysdate) BETWEEN pap.effective_start_date AND pap.effective_end_dateAnd Trunc(Sysdate) Between Paa.Effective_Start_Date And Paa.Effective_End_DateAND psth.transaction_history_id = pssh.transaction_history_id --and psah.transaction_history_id = psth.transaction_history_idAND psvh.step_history_id(+) = pssh.step_history_id--AND 1 =-- CASE-- WHEN lower(:p_category) = 'leave'-- AND psth.transaction_group ='ABSENCE_MGMT'-- AND NVL(to_date(DECODE(pssh.information9,'CONFIRMED',pssh.information1,'PLANNED',pssh.information3),'RRRR-MM-DD'),:p_from_date) BETWEEN :p_from_date AND :p_to_date-- AND NVL(to_date(DECODE(pssh.information9,'CONFIRMED',pssh.information2,'PLANNED',pssh.information4),'RRRR-MM-DD'),:p_to_date) BETWEEN :p_from_date AND :p_to_date-- THEN 1-- WHEN lower(:p_category) != 'leave'-- AND psvh.name = 'P_STRUCTURE_NAME'-- AND psvh.value = :p_category-- AND TRUNC(psth.creation_date) BETWEEN NVL(:p_from_date,TRUNC(sysdate)) AND NVL(:p_to_date,TRUNC(sysdate))-- THEN 1-- ELSE 2-- ENDAND wf.item_type = psth.item_typeAND wf.item_key = psth.item_keyAND pap.person_id = NVL(:P_EMPLOYEE_ID,pap.person_id)AND haou.organization_id = NVL(:P_DEPT_ID,haou.organization_id)--AND COALESCE(-- (SELECT name-- FROM per_absence_attendance_types-- WHERE absence_attendance_type_id = pssh.information5-- ),:P_TYPE,'1') = COALESCE(:P_TYPE, (SELECT name-- FROM per_absence_attendance_types-- Where Absence_Attendance_Type_Id = Pssh.Information5-- ),'1')--AND lower(wf.l_action) = lower(NVL(:p_status,wf.l_action))AND wf.notification_id IN (SELECT MAX(notification_id) FROM wf_notifications WHERE NVL(from_role,'SYSADMIN') != 'SYSADMIN' Group By Item_Key)--ORDER BY sent;