/* Vendor Usage — detail (DatawarehouseNCM) Fact: dbo.FactVendorUsage BackOffice: frmRptVendorUsage Crystal: VendorUsage_HHG.rpt / VendorUsage_TLV.rpt / VendorUsage_MiscOrders.rpt UsageReportType: 'HHG' | 'TLV' | 'MiscOrders' OrderDate is ROLOrderDate (HHG), DateBooked (TLV), or OrderSentDate (MiscOrders). ServiceType: 0=Both, 1=Domestic, 2=International (form radios / Pm-ServiceType). Alaska filter (HHG only in the form): DPTWorkState / DSTWorkState. */ DECLARE @UsageReportType varchar(20) = 'HHG'; -- HHG | TLV | MiscOrders DECLARE @StartDate datetime = '2026-01-01'; DECLARE @EndDate datetime = '2026-01-31'; DECLARE @CorpCode varchar(15) = NULL; -- NULL / '' = all DECLARE @ParentRollup bit = 0; DECLARE @SrvcProvider varchar(4) = NULL; DECLARE @VendorParentID int = NULL; -- NULL / 0 = all DECLARE @ServiceType smallint = NULL; -- NULL / 0 = Both; 1=Domestic; 2=International DECLARE @AlaskaOnly bit = 0; SELECT f.UsageReportType, f.CorpCode, f.FormalName, f.ParentCompany, f.TEFileNo, f.TELastName, f.TEFirstName, f.ServiceType, f.SrvcProvider, f.SrvcFirstName, f.SrvcLastName, f.OrderDate, f.VendorParentID, f.CompanyName, f.CompanySubName, f.VendorID, f.HHGAutoShipment, f.ServiceCode, f.ServiceDescription, f.DPTWorkState, f.DSTWorkState FROM dbo.FactVendorUsage f WHERE f.UsageReportType = @UsageReportType AND f.OrderDate BETWEEN @StartDate AND @EndDate AND ( (@ParentRollup = 0 AND (@CorpCode IS NULL OR @CorpCode = '' OR f.CorpCode = @CorpCode)) OR (@ParentRollup = 1 AND (@CorpCode IS NULL OR @CorpCode = '' OR f.ParentCompany = @CorpCode OR f.CorpCode = @CorpCode)) ) AND (@SrvcProvider IS NULL OR @SrvcProvider = '' OR f.SrvcProvider = @SrvcProvider) AND (@VendorParentID IS NULL OR @VendorParentID = 0 OR f.VendorParentID = @VendorParentID) AND (@ServiceType IS NULL OR @ServiceType = 0 OR f.ServiceType = @ServiceType) AND ( @AlaskaOnly = 0 OR f.DPTWorkState IN ('AK', 'Alaska') OR f.DSTWorkState IN ('AK', 'Alaska') ) ORDER BY f.CompanyName, f.CorpCode, f.OrderDate, f.TEFileNo;