-- ============================================= -- Author: -- Create date: <23.09.2009> -- Description: -- ============================================= CREATE PROCEDURE [spConsignor] -- Input parameters: -- DataAreaID = Location ID, PackOrderID = Search key for order and packingslip, CustID = Search key for customers @DataAreaID char(15), @PackOrderID char(20), @CustID char(20) AS DECLARE @PackslipBool AS bit DECLARE @OrderBool AS bit BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; --Checks if its a packingslip number or a order number SET @PackslipBool = (SELECT COUNT(PACKINGSLIPID) FROM CUSTPACKINGSLIPJOUR WHERE LTRIM(PACKINGSLIPID) = @PackOrderID AND DATAAREAID = @DataAreaID) IF @PackslipBool <> 1 SET @OrderBool = (SELECT COUNT(SALESID) FROM SALESTABLE WHERE LTRIM(SALESID) = @PackOrderID AND DATAAREAID = @DataAreaID) -- Insert statements for procedure here -- If the packingslip number exist, this SELECT statement will be executed IF @PackslipBool = 1 SELECT -- Customer NULL AS CustomerNum_Customer, NULL AS Name1_Customer, NULL AS Name2_Customer, NULL AS StreetAddress1_Customer, NULL AS StreetAddress2_Customer, NULL AS StreetAddress3_Customer, NULL AS Postcode_Customer, NULL AS City_Customer, NULL AS Mobile_Customer, NULL AS Phone_Customer, NULL AS Email_Customer, NULL AS Fax_Customer, NULL AS PostOfficeBox_Customer, NULL AS PostOfficeBoxCity_Customer, NULL AS PostOfficeBoxPostcode_Customer, NULL AS CountryName_Customer, NULL AS CustomerOrigin_Customer, NULL AS Attention_Customer, NULL AS Contact_Customer, NULL AS ReceiverRef_Customer, NULL AS OurRef_Customer, NULL AS MessageToCarrier_Customer, NULL AS MessageToDriver_Customer, NULL AS MessageToReceiver_Customer, NULL AS PurchaseNo_Customer, NULL AS ShipmentTypeNo_Customer, -- Order CustomerOrder / CustomerOrderCopy LTRIM(CUSTTABLE.ACCOUNTNUM) AS CustomerNum_Order, CUSTPACKINGSLIPJOUR.PACKINGSLIPID AS OrderNumber_Order, NULL AS Name1_Order, NULL AS Name2_Order, NULL AS StreetAddress1_Order, NULL AS StreetAddress2_Order, NULL AS StreetAddress3_Order, NULL AS Postcode_Order, NULL AS City_Order, NULL AS Mobile_Order, NULL AS Phone_Order, NULL AS Email_Order, NULL AS Fax_Order, NULL AS PostOfficeBox_Order, NULL AS PostOfficeBoxCity_Order, NULL AS PostOfficeBoxPostcode_Order, NULL AS CountryName_Order, NULL AS CustomerOrigin_Order, NULL AS Attention_Order, CUSTPACKINGSLIPJOUR.CUSTOMERREF AS Contact_Order, CUSTPACKINGSLIPJOUR.SALESID AS ReceiverRef_Order, NULL AS OurRef_Order, NULL AS MessageToCarrier_Order, NULL AS MessageToDriver_Order, NULL AS MessageToReceiver_Order, NULL AS PurchaseNo_Order, NULL AS ShipmentTypeNo_Order, -- Delivery NULL AS CustomerNum_Delivery, CUSTPACKINGSLIPJOUR.DELIVERYNAME AS Name1_Delivery, NULL AS Name2_Delivery, CUSTPACKINGSLIPJOUR.DELIVERYSTREET AS StreetAddress1_Delivery, NULL AS StreetAddress2_Delivery, NULL AS StreetAddress3_Delivery, CUSTPACKINGSLIPJOUR.DLVZIPCODE AS Postcode_Delivery, CUSTPACKINGSLIPJOUR.DELIVERYCITY AS City_Delivery, NULL AS Mobile_Delivery, NULL AS Phone_Delivery, NULL AS Email_Delivery, NULL AS Fax_Delivery, NULL AS PostOfficeBox_Delivery, NULL AS PostOfficeBoxCity_Delivery, NULL AS PostOfficeBoxPostcode_Delivery, CUSTPACKINGSLIPJOUR.DLVCOUNTRY AS CountryName_Delivery, NULL AS CustomerOrigin_Delivery, NULL AS Attention_Delivery, NULL AS Contact_Delivery, NULL AS ReceiverRef_Delivery, NULL AS OurRef_Delivery, NULL AS MessageToCarrier_Delivery, NULL AS MessageToDriver_Delivery, NULL AS MessageToReceiver_Delivery, NULL AS PurchaseNo_Delivery, NULL AS ShipmentTypeNo_Delivery, -- Invoice NULL AS CustomerNum_Invoice, NULL AS Name1_Invoice, NULL AS Name2_Invoice, NULL AS StreetAddress1_Invoice, NULL AS StreetAddress2_Invoice, NULL AS StreetAddress3_Invoice, NULL AS Postcode_Invoice, NULL AS City_Invoice, NULL AS Mobile_Invoice, NULL AS Phone_Invoice, NULL AS Email_Invoice, NULL AS Fax_Invoice, CUSTTABLE.STREET AS PostOfficeBox_Invoice, CUSTTABLE.CITY AS PostOfficeBoxCity_Invoice, CUSTTABLE.ZIPCODE AS PostOfficeBoxPostcode_Invoice, CUSTTABLE.COUNTRY AS CountryName_Invoice, NULL AS CustomerOrigin_Invoice, NULL AS Attention_Invoice, NULL AS Contact_Invoice, NULL AS ReceiverRef_Invoice, NULL AS OurRef_Invoice, NULL AS MessageToCarrier_Invoice, NULL AS MessageToDriver_Invoice, NULL AS MessageToReceiver_Invoice, NULL AS PurchaseNo_Invoice, NULL AS ShipmentTypeNo_Invoice, -- Contact NULL AS ContactNum_Contact, CUSTTABLE.NAME AS Name1_Contact, NULL AS Name2_Contact, CUSTTABLE.STREET AS StreetAddress1_Contact, NULL AS StreetAddress2_Contact, NULL AS StreetAddress3_Contact, CUSTTABLE.ZIPCODE AS Postcode_Contact, CUSTTABLE.CITY AS City_Contact, CUSTTABLE.CELLULARPHONE AS Mobile_Contact, CUSTTABLE.PHONE AS Phone_Contact, CUSTTABLE.EMAIL AS Email_Contact, CUSTTABLE.TELEFAX AS Fax_Contact, NULL AS PostOfficeBox_Contact, NULL AS PostOfficeBoxCity_Contact, NULL AS PostOfficeBoxPostcode_Contact, CUSTTABLE.COUNTRY AS CountryName_Contact, NULL AS CustomerOrigin_Contact, NULL AS Attention_Contact, NULL AS Contact_Contact, NULL AS CustomerNum_Contact, -- Package 1 AS PackagesCount, NULL AS PackagesMarking, NULL AS PackagesContents, CUSTPACKINGSLIPJOUR.[WEIGHT] * 1000 AS PackagesWeight, NULL AS PackagesHeight, NULL AS PackagesLength, NULL AS PackagesWidth , NULL AS PackagesVolume, NULL AS CODAccount, NULL AS CODAmount, NULL AS CODKID, NULL AS CODReference, NULL AS InsuranceAmount, NULL AS InsuranceCategory, NULL AS InsurancePolicyNo, NULL AS DeliveryTerms, NULL AS Department, NULL AS InvoiceNumber, NULL AS PaymentTerms, NULL AS PaymentType, NULL AS ProjectName, NULL AS ProjectNumber, CUSTPACKINGSLIPJOUR.DLVMode AS CarrierCode, NULL AS SearchKeyOrder1, NULL AS SearchKeyOrder2, NULL AS SearchKeyInvoiceNum, NULL AS SearchKeyCustomerNum, NULL AS SearchKeyContactNum, NULL AS Link_Table1, NULL AS Link_Table2, NULL AS Link_Table3, NULL AS Link_Table4, NULL AS Link_Table5, NULL AS Link_Table6, NULL AS Link_Table7, NULL AS Link_Table8, NULL AS Link_Table9, NULL AS Link_Table10 FROM CUSTTABLE LEFT JOIN CUSTPACKINGSLIPJOUR ON CUSTTABLE.ACCOUNTNUM = CUSTPACKINGSLIPJOUR.ORDERACCOUNT WHERE LTRIM(CUSTPACKINGSLIPJOUR.PACKINGSLIPID) = @PackOrderID AND CUSTPACKINGSLIPJOUR.DATAAREAID = @DataAreaID AND CUSTTABLE.DATAAREAID = @DataAreaID ELSE BEGIN -- If the order number exist, this SELECT statement will be executed IF @OrderBool = 1 SELECT -- Customer NULL AS CustomerNum_Customer, NULL AS Name1_Customer, NULL AS Name2_Customer, NULL AS StreetAddress1_Customer, NULL AS StreetAddress2_Customer, NULL AS StreetAddress3_Customer, NULL AS Postcode_Customer, NULL AS City_Customer, NULL AS Mobile_Customer, NULL AS Phone_Customer, NULL AS Email_Customer, NULL AS Fax_Customer, NULL AS PostOfficeBox_Customer, NULL AS PostOfficeBoxCity_Customer, NULL AS PostOfficeBoxPostcode_Customer, NULL AS CountryName_Customer, NULL AS CustomerOrigin_Customer, NULL AS Attention_Customer, NULL AS Contact_Customer, NULL AS ReceiverRef_Customer, NULL AS OurRef_Customer, NULL AS MessageToCarrier_Customer, NULL AS MessageToDriver_Customer, NULL AS MessageToReceiver_Customer, NULL AS PurchaseNo_Customer, NULL AS ShipmentTypeNo_Customer, -- Order CustomerOrder / CustomerOrderCopy LTRIM(CUSTTABLE.ACCOUNTNUM) AS CustomerNum_Order, SALESTABLE.SALESID AS OrderNumber_Order, NULL AS Name1_Order, NULL AS Name2_Order, NULL AS StreetAddress1_Order, NULL AS StreetAddress2_Order, NULL AS StreetAddress3_Order, NULL AS Postcode_Order, NULL AS City_Order, NULL AS Mobile_Order, NULL AS Phone_Order, NULL AS Email_Order, NULL AS Fax_Order, NULL AS PostOfficeBox_Order, NULL AS PostOfficeBoxCity_Order, NULL AS PostOfficeBoxPostcode_Order, NULL AS CountryName_Order, NULL AS CustomerOrigin_Order, NULL AS Attention_Order, SALESTABLE.CUSTOMERREF AS Contact_Order, CUSTPACKINGSLIPJOUR.PACKINGSLIPID AS ReceiverRef_Order, NULL AS OurRef_Order, NULL AS MessageToCarrier_Order, NULL AS MessageToDriver_Order, NULL AS MessageToReceiver_Order, NULL AS PurchaseNo_Order, NULL AS ShipmentTypeNo_Order, -- Delivery NULL AS CustomerNum_Delivery, SALESTABLE.DELIVERYNAME AS Name1_Delivery, NULL AS Name2_Delivery, SALESTABLE.DELIVERYSTREET AS StreetAddress1_Delivery, NULL AS StreetAddress2_Delivery, NULL AS StreetAddress3_Delivery, SALESTABLE.DELIVERYZIPCODE AS Postcode_Delivery, SALESTABLE.DELIVERYCITY AS City_Delivery, NULL AS Mobile_Delivery, NULL AS Phone_Delivery, NULL AS Email_Delivery, NULL AS Fax_Delivery, NULL AS PostOfficeBox_Delivery, NULL AS PostOfficeBoxCity_Delivery, NULL AS PostOfficeBoxPostcode_Delivery, SALESTABLE.DELIVERYCOUNTRY AS CountryName_Delivery, NULL AS CustomerOrigin_Delivery, NULL AS Attention_Delivery, NULL AS Contact_Delivery, NULL AS ReceiverRef_Delivery, NULL AS OurRef_Delivery, NULL AS MessageToCarrier_Delivery, NULL AS MessageToDriver_Delivery, NULL AS MessageToReceiver_Delivery, NULL AS PurchaseNo_Delivery, NULL AS ShipmentTypeNo_Delivery, -- Invoice NULL AS CustomerNum_Invoice, NULL AS Name1_Invoice, NULL AS Name2_Invoice, NULL AS StreetAddress1_Invoice, NULL AS StreetAddress2_Invoice, NULL AS StreetAddress3_Invoice, NULL AS Postcode_Invoice, NULL AS City_Invoice, NULL AS Mobile_Invoice, NULL AS Phone_Invoice, NULL AS Email_Invoice, NULL AS Fax_Invoice, CUSTTABLE.STREET AS PostOfficeBox_Invoice, CUSTTABLE.CITY AS PostOfficeBoxCity_Invoice, CUSTTABLE.ZIPCODE AS PostOfficeBoxPostcode_Invoice, CUSTTABLE.COUNTRY AS CountryName_Invoice, NULL AS CustomerOrigin_Invoice, NULL AS Attention_Invoice, NULL AS Contact_Invoice, NULL AS ReceiverRef_Invoice, NULL AS OurRef_Invoice, NULL AS MessageToCarrier_Invoice, NULL AS MessageToDriver_Invoice, NULL AS MessageToReceiver_Invoice, NULL AS PurchaseNo_Invoice, NULL AS ShipmentTypeNo_Invoice, -- Contact NULL AS ContactNum_Contact, CUSTTABLE.NAME AS Name1_Contact, NULL AS Name2_Contact, CUSTTABLE.STREET AS StreetAddress1_Contact, NULL AS StreetAddress2_Contact, NULL AS StreetAddress3_Contact, CUSTTABLE.ZIPCODE AS Postcode_Contact, CUSTTABLE.CITY AS City_Contact, CUSTTABLE.CELLULARPHONE AS Mobile_Contact, CUSTTABLE.PHONE AS Phone_Contact, CUSTTABLE.EMAIL AS Email_Contact, CUSTTABLE.TELEFAX AS Fax_Contact, NULL AS PostOfficeBox_Contact, NULL AS PostOfficeBoxCity_Contact, NULL AS PostOfficeBoxPostcode_Contact, CUSTTABLE.COUNTRY AS CountryName_Contact, NULL AS CustomerOrigin_Contact, NULL AS Attention_Contact, NULL AS Contact_Contact, NULL AS CustomerNum_Contact, -- Package NULL AS PackagesCount, NULL AS PackagesMarking, NULL AS PackagesContents, NULL AS PackagesWeight, NULL AS PackagesHeight, NULL AS PackagesLength, NULL AS PackagesWidth , NULL AS PackagesVolume, NULL AS CODAccount, NULL AS CODAmount, NULL AS CODKID, NULL AS CODReference, NULL AS InsuranceAmount, NULL AS InsuranceCategory, NULL AS InsurancePolicyNo, NULL AS DeliveryTerms, NULL AS Department, NULL AS InvoiceNumber, NULL AS PaymentTerms, NULL AS PaymentType, NULL AS ProjectName, NULL AS ProjectNumber, SALESTABLE.DLVMode AS CarrierCode, NULL AS SearchKeyOrder1, NULL AS SearchKeyOrder2, NULL AS SearchKeyInvoiceNum, NULL AS SearchKeyCustomerNum, NULL AS SearchKeyContactNum, NULL AS Link_Table1, NULL AS Link_Table2, NULL AS Link_Table3, NULL AS Link_Table4, NULL AS Link_Table5, NULL AS Link_Table6, NULL AS Link_Table7, NULL AS Link_Table8, NULL AS Link_Table9, NULL AS Link_Table10 FROM CUSTTABLE LEFT JOIN SALESTABLE ON CUSTTABLE.ACCOUNTNUM = SALESTABLE.CUSTACCOUNT INNER JOIN CUSTPACKINGSLIPJOUR ON SALESTABLE.SALESID = CUSTPACKINGSLIPJOUR.SALESID WHERE LTRIM(SALESTABLE.SALESID) = @PackOrderID AND SALESTABLE.DATAAREAID = @DataAreaID AND CUSTTABLE.DATAAREAID = @DataAreaID ELSE BEGIN -- If the input parameter @PackOrderID is empty(=0) and the input parameter -- for @custID is provided and exists, this SELECT statement will be executed IF @CustID != ' SELECT -- Customer NULL AS CustomerNum_Customer, NULL AS Name1_Customer, NULL AS Name2_Customer, NULL AS StreetAddress1_Customer, NULL AS StreetAddress2_Customer, NULL AS StreetAddress3_Customer, NULL AS Postcode_Customer, NULL AS City_Customer, NULL AS Mobile_Customer, NULL AS Phone_Customer, NULL AS Email_Customer, NULL AS Fax_Customer, NULL AS PostOfficeBox_Customer, NULL AS PostOfficeBoxCity_Customer, NULL AS PostOfficeBoxPostcode_Customer, NULL AS CountryName_Customer, NULL AS CustomerOrigin_Customer, NULL AS Attention_Customer, NULL AS Contact_Customer, NULL AS ReceiverRef_Customer, NULL AS OurRef_Customer, NULL AS MessageToCarrier_Customer, NULL AS MessageToDriver_Customer, NULL AS MessageToReceiver_Customer, NULL AS PurchaseNo_Customer, NULL AS ShipmentTypeNo_Customer, -- Order CustomerOrder / CustomerOrderCopy LTRIM(CUSTTABLE.ACCOUNTNUM) AS CustomerNum_Order, NULL AS OrderNumber_Order, NULL AS Name1_Order, NULL AS Name2_Order, NULL AS StreetAddress1_Order, NULL AS StreetAddress2_Order, NULL AS StreetAddress3_Order, NULL AS Postcode_Order, NULL AS City_Order, NULL AS Mobile_Order, NULL AS Phone_Order, NULL AS Email_Order, NULL AS Fax_Order, NULL AS PostOfficeBox_Order, NULL AS PostOfficeBoxCity_Order, NULL AS PostOfficeBoxPostcode_Order, NULL AS CountryName_Order, NULL AS CustomerOrigin_Order, NULL AS Attention_Order, NULL AS Contact_Order, NULL AS ReceiverRef_Order, NULL AS OurRef_Order, NULL AS MessageToCarrier_Order, NULL AS MessageToDriver_Order, NULL AS MessageToReceiver_Order, NULL AS PurchaseNo_Order, NULL AS ShipmentTypeNo_Order, -- Delivery LTRIM(CUSTTABLE.ACCOUNTNUM) AS CustomerNum_Delivery, CUSTTABLE.NAME AS Name1_Delivery, NULL AS Name2_Delivery, CUSTTABLE.STREET AS StreetAddress1_Delivery, NULL AS StreetAddress2_Delivery, NULL AS StreetAddress3_Delivery, CUSTTABLE.ZIPCODE AS Postcode_Delivery, CUSTTABLE.CITY AS City_Delivery, NULL AS Mobile_Delivery, NULL AS Phone_Delivery, NULL AS Email_Delivery, NULL AS Fax_Delivery, NULL AS PostOfficeBox_Delivery, NULL AS PostOfficeBoxCity_Delivery, NULL AS PostOfficeBoxPostcode_Delivery, CUSTTABLE.COUNTRY AS CountryName_Delivery, NULL AS CustomerOrigin_Delivery, NULL AS Attention_Delivery, NULL AS Contact_Delivery, NULL AS ReceiverRef_Delivery, NULL AS OurRef_Delivery, NULL AS MessageToCarrier_Delivery, NULL AS MessageToDriver_Delivery, NULL AS MessageToReceiver_Delivery, NULL AS PurchaseNo_Delivery, NULL AS ShipmentTypeNo_Delivery, -- Invoice NULL AS CustomerNum_Invoice, NULL AS Name1_Invoice, NULL AS Name2_Invoice, NULL AS StreetAddress1_Invoice, NULL AS StreetAddress2_Invoice, NULL AS StreetAddress3_Invoice, NULL AS Postcode_Invoice, NULL AS City_Invoice, NULL AS Mobile_Invoice, NULL AS Phone_Invoice, NULL AS Email_Invoice, NULL AS Fax_Invoice, CUSTTABLE.STREET AS PostOfficeBox_Invoice, CUSTTABLE.CITY AS PostOfficeBoxCity_Invoice, CUSTTABLE.ZIPCODE AS PostOfficeBoxPostcode_Invoice, CUSTTABLE.COUNTRY AS CountryName_Invoice, NULL AS CustomerOrigin_Invoice, NULL AS Attention_Invoice, NULL AS Contact_Invoice, NULL AS ReceiverRef_Invoice, NULL AS OurRef_Invoice, NULL AS MessageToCarrier_Invoice, NULL AS MessageToDriver_Invoice, NULL AS MessageToReceiver_Invoice, NULL AS PurchaseNo_Invoice, NULL AS ShipmentTypeNo_Invoice, -- Contact NULL AS ContactNum_Contact, NULL AS Name1_Contact, NULL AS Name2_Contact, NULL AS StreetAddress1_Contact, NULL AS StreetAddress2_Contact, NULL AS StreetAddress3_Contact, NULL AS Postcode_Contact, NULL AS City_Contact, CUSTTABLE.CELLULARPHONE AS Mobile_Contact, CUSTTABLE.PHONE AS Phone_Contact, CUSTTABLE.EMAIL AS Email_Contact, CUSTTABLE.TELEFAX AS Fax_Contact, NULL AS PostOfficeBox_Contact, NULL AS PostOfficeBoxCity_Contact, NULL AS PostOfficeBoxPostcode_Contact, NULL AS CountryName_Contact, NULL AS CustomerOrigin_Contact, NULL AS Attention_Contact, NULL AS Contact_Contact, NULL AS CustomerNum_Contact, -- Package NULL AS PackagesCount, NULL AS PackagesMarking, NULL AS PackagesContents, NULL AS PackagesWeight, NULL AS PackagesHeight, NULL AS PackagesLength, NULL AS PackagesWidth , NULL AS PackagesVolume, NULL AS CODAccount, NULL AS CODAmount, NULL AS CODKID, NULL AS CODReference, NULL AS InsuranceAmount, NULL AS InsuranceCategory, NULL AS InsurancePolicyNo, NULL AS DeliveryTerms, NULL AS Department, NULL AS InvoiceNumber, NULL AS PaymentTerms, NULL AS PaymentType, NULL AS ProjectName, NULL AS ProjectNumber, NULL AS CarrierCode, NULL AS SearchKeyOrder1, NULL AS SearchKeyOrder2, NULL AS SearchKeyInvoiceNum, NULL AS SearchKeyCustomerNum, NULL AS SearchKeyContactNum, NULL AS Link_Table1, NULL AS Link_Table2, NULL AS Link_Table3, NULL AS Link_Table4, NULL AS Link_Table5, NULL AS Link_Table6, NULL AS Link_Table7, NULL AS Link_Table8, NULL AS Link_Table9, NULL AS Link_Table10 FROM CUSTTABLE WHERE LTRIM(CUSTTABLE.ACCOUNTNUM) = @CustID AND CUSTTABLE.DATAAREAID = @DataAreaID END END END GO