sql 加载约会变更表和业务逻辑
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 加载约会变更表和业务逻辑相关的知识,希望对你有一定的参考价值。
--=================================================
-- Creator: Megan Danczyk
-- Created Date: 3/25/19
-- Modified Date: --
-- Purpose: Data Dictionary for appointment changes and reason codes. Business Logic is incldued for each type.
-- Modified Reason:
--=================================================
--PRIMARY TABLE JOIN STRUCTURE FOR LOAD LEVEL APPOINTMENT CHANGES
SELECT TOP 100
LAC.LoadGuid --UniqueIdentifier That directly ties to dbo.tblloads.
,LAC.LoadAppointmentChangeReasonId --Integer representing change reason. Decoded with dbo.loadappointmentchangereason
,LAC.Notes --Notes associated with appointment change. (Possibly useful for OdinText type solutions?)
,LAC.CreatedBy --Full Name of individual who changed appointment. Ties to dbo.tblusers.fullname
,LAC.CreatedDate --DateTime for when appointment(s) where changed. -- Date Used for Rolled Date
,LACR.Name --Appointment Change Reason
,CLACR.Name --Associated Carrier Change Reason
FROM EchoOptimizer.dbo.LoadAppointmentChange LAC
LEFT JOIN EchoOptimizer.dbo.LoadAppointmentChangeReason LACR ON LAC.LoadAppointmentChangeReasonId = LAC.LoadAppointmentChangeReasonId
LEFT JOIN EchoOptimizer.dbo.CarrierLoadAppointmentChangeReason CLACR ON LAC.CarrierLoadAppointmentChangeReasonId = CLACR.CarrierLoadAppointmentChangeReasonId
--APPOINTMENT CHANGE REASON BUSINESS LOGIC
SELECT LoadAppointmentChangeReasonId --Id Used to Tie to dbo.LoadAppointmentChange
,Name --Reason Code Displayed
,IsActive -- Active Flag (Historic Reasons Included In Table)
,CASE WHEN LoadAppointmentChangeReasonId IN (3,7,12,27,28) THEN 1 ELSE 0 END CustomerReason
,CASE WHEN LoadAppointmentChangeReasonId IN (2,8,9,10,11,18,20) THEN 1 ELSE 0 END CarrierReason
,CASE WHEN LoadAppointmentChangeReasonId IN (5,6,13,15,16,17,21,25,26) THEN 1 ELSE 0 END EchoSalesOpsReason
,CASE WHEN LoadAppointmentChangeReasonId IN (1,14,18,19,24,26) THEN 1 ELSE 0 END EchoSourcingReason
,CASE WHEN LoadAppointmentChangeReasonId IN (4,22,23,29) THEN 1 ELSE 0 END NonIssueReason
FROM EchoOptimizer.dbo.LoadAppointmentChangeReason
--APPOINTMENT CARRIER CHANGE REASON BUSINESS LOGIC
SELECT CarrierLoadAppointmentChangeReasonId --Id Used to Tie to dbo.LoadAppointmentChange
,Name --Reason Code Displayed
,IsActive --Active Flag (Historic Reasons Included In Table)
,CASE WHEN CarrierLoadAppointmentChangeReasonId IN (1,2,4,6,7,8,10) THEN 1 ELSE 0 END CarrierReason
,CASE WHEN CarrierLoadAppointmentChangeReasonId IN (3,5,9) THEN 1 ELSE 0 END NonCarrierReason
,CASE WHEN CarrierLoadAppointmentChangeReasonId IN (11) THEN 1 ELSE 0 END NonIssue
FROM EchoOptimizer.dbo.CarrierLoadAppointmentChangeReason
--APPOINTMENT CHANGE DETAILS SPECIFIC TO WHAT IS BEING CHANGED
SELECT TOP 100
LoadAppointmentChangeDetailId
,LoadAppointmentChangeId --Id Used to Tie to dbo.LoadAppointmentChange
,LoadStopId --Id Used to Tie to dbo.tblloadstops
,AppointmentType --Appointment Type Changed (PickupTo, PickupFrom, DeliverTo, DeliverArrival, PickupArrival)
,OriginalDate --Previous Datetime Entered
,NewDate --New Datetime Entered (When Appointment Type = PickupTo OR DeliverTo AND CAST(OriginalDate AS DATE) < CAST(NewDate AS DATE), the change is considered a rolled appointment)
,CreatedBy --Rep Changing Datetime (tie to dbo.tblusers on FullName)
,CreatedDate --Date Change occured. Not as important as datetime from dbo.LoadAppointmentChange
FROM EchoOptimizer.dbo.LoadAppointmentChangeDetail
以上是关于sql 加载约会变更表和业务逻辑的主要内容,如果未能解决你的问题,请参考以下文章