Quantcast
Viewing all articles
Browse latest Browse all 30

Please tune the code

Dear All, Have wrote a script. Could you please tune the code. bit urgent. select J.RouteID TripID, J.JourneyAlias Journey_Trip_Id, J.OwningDepotDropPointID Depot, JD.DropPointID LocationID, JD.TimeWindowStart Appointment_Start, JD.TimeWindowEnd Appointment_End, case when (JD.PTA < JD.TimeWindowStart and JD.TimeWindowStart < JD.PTD) then JD.TimeWindowStart else JD.PTA end as PlannedArrival, JD.PTD PlannedDeparture, case when JD.ConfirmedArrivalTime is null then JD.ATA else JD.ConfirmedArrivalTime end as ActualArrival, case when JD.ConfirmedDepartureTime is null then JD.ATD else JD.ConfirmedDepartureTime end as ActualDeparture, case when (J.OwningDepotDropPointID in ('SKDC', 'WNDC', 'KKRDC', 'KKRFDC', 'BBTDC') and ST.SiteTypeName IN ('HyperExtra', 'Hypermarket', 'Compact Hypermarket', 'TaladExpress')) then '1:00:00' else --Added Somadatta for Talad case when (J.OwningDepotDropPointID in ('SKDC', 'WNDC', 'KKRDC', 'KKRFDC', 'BBTDC','CHMRDC', 'LLKDC') and ST.SiteTypeName = 'Talad') then tmp.Volume else case when (J.OwningDepotDropPointID in ('SKDC', 'WNDC', 'KKRDC', 'KKRFDC', 'BBTDC') and ST.SiteTypeName in ('HBA', 'Convenience', 'Express')) then '00:30:00' else case when (J.OwningDepotDropPointID in ('CHMRDC', 'LLKDC') and ST.SiteTypeName in ('HyperExtra', 'Hypermarket', 'Compact Hypermarket', 'TaladExpress')) then '00:45:00' else case when (J.OwningDepotDropPointID in ('CHMRDC', 'LLKDC') and ST.SiteTypeName in ('HBA', 'Convenience', 'Express')) then '00:30:00' end end end end end as PlannedTurnaroundTime, (case when JD.ConfirmedDepartureTime is null then JD.ATD else JD.ConfirmedDepartureTime end - case when JD.ConfirmedArrivalTime is null then JD.ATA else JD.ConfirmedArrivalTime end) as ActualTurnaround from tbl_J JD , tbl_Jo J , tbl_Si ST ,(select cd.PlannedVolume, JD.JourneyDropID,JD.PTA, CAST((Convert(time, CONVERT(datetime, '00:20:00' ) + CONVERT(datetime, (convert(varchar(10), dateadd(second, (((datepart(hour,'00:01:30') * 360) + (datepart(minute,'00:01:30') * 60) + datepart(second,'00:01:30'))* CD.PlannedVolume), 0), 108)) ))) as char(8)) as Volume from tbl_C CD, tbl_Co C, tbl_Con CS, tbl_Jou JD where IsNumeric(JD.DropPointID) = 1 AND JD.PTA BETWEEN '2014-04-01 00:00:00' and '2014-09-12 00:00:00' --change the date accordingly and CS.JourneyDropID = JD.JourneyDropID and C.ConsignmentSiteID = CS.ConsignmentSiteID and CD.ConsignmentHeaderID = C.ConsignmentHeaderID )tmp where IsNumeric(JD.DropPointID) = 1 AND JD.PTA BETWEEN '2014-04-01 00:00:00' and '2014-09-12 00:00:00' AND J.Status = 'C' and JD.JourneyID = J.JourneyID and JD.JourneyDropID=tmp.JourneyDropID and exists (select 1 from tbl_DropPoints DP where DP.DropPointID = JD.DropPointID and ST.SiteTypeID = DP.SiteTypeID)

Viewing all articles
Browse latest Browse all 30

Trending Articles