
[dbo].[GetARCCustomerContacts_XLedger]
create procedure [dbo].[GetARCCustomerContacts_XLedger]
@inCustomerNumber varchar(15)
as
begin
set nocount on
select
ARCCustomerContactId = ARCCustomerContact.ARCCustomerContactId,
CustomerNumber = AccountingCustomer.CustomerNumber,
CustomerAddressCode = convert( varchar(15), null ),
Contact = ARCCustomerContact.ContactPerson,
Email = ARCCustomerContact.EmailAddress,
Address1 = ARCCustomerContactAddress.Address1,
Address2 = ARCCustomerContactAddress.Address2,
Address3 = ARCCustomerContactAddress.Address3,
City = ARCCustomerContactAddress.City,
[State] = ARCCustomerContactAddress.[State],
Zip = ARCCustomerContactAddress.PostalCode,
Country = CountryCodeStandard.CountryName,
CountryCodeStandardFID = CountryCodeStandard.CountryCodeStandardID,
Phone1 = dbo.FullPhoneNumberDigits( Phone1Phone.AreaCode, Phone1Phone.LocalNumber ),
Phone1CountryCodeStandardFID = Phone1Phone.CountryCodeStandardFID,
Phone1Ext = Phone1Phone.Extension,
Phone2 = dbo.FullPhoneNumberDigits( Phone2Phone.AreaCode, Phone2Phone.LocalNumber ),
Phone2Ext = Phone2Phone.Extension,
Phone3 = dbo.FullPhoneNumberDigits( Phone3Phone.AreaCode, Phone3Phone.LocalNumber ),
Phone3Ext = Phone3Phone.Extension,
Fax = dbo.FullPhoneNumberDigits( FaxPhone.AreaCode, FaxPhone.LocalNumber )
from AccountingCustomer
inner join ARCCustomerContact on ARCCustomerContact.AccountingCustomerFid = AccountingCustomer.AccountingCustomerId
inner join AddressType on ( AddressType.TypeName = 'Main' )
inner join ARCCustomerContactPhoneType as Phone1PhoneType on ( Phone1PhoneType.TypeName = 'Phone1' )
inner join ARCCustomerContactPhoneType as Phone2PhoneType on ( Phone2PhoneType.TypeName = 'Phone2' )
inner join ARCCustomerContactPhoneType as Phone3PhoneType on ( Phone3PhoneType.TypeName = 'Phone3' )
inner join ARCCustomerContactPhoneType as FaxPhoneType on ( FaxPhoneType.TypeName = 'Fax' )
left outer join ARCCustomerContactPhoneNumber as Phone1Phone on
(
Phone1Phone.ARCCustomerContactFid = ARCCustomerContact.ARCCustomerContactId and
Phone1Phone.ARCCustomerContactPhoneTypeFid = Phone1PhoneType.ARCCustomerContactPhoneTypeId
)
left outer join ARCCustomerContactPhoneNumber as Phone2Phone on
(
Phone2Phone.ARCCustomerContactFid = ARCCustomerContact.ARCCustomerContactId and
Phone2Phone.ARCCustomerContactPhoneTypeFid = Phone2PhoneType.ARCCustomerContactPhoneTypeId
)
left outer join ARCCustomerContactPhoneNumber as Phone3Phone on
(
Phone3Phone.ARCCustomerContactFid = ARCCustomerContact.ARCCustomerContactId and
Phone3Phone.ARCCustomerContactPhoneTypeFid = Phone3PhoneType.ARCCustomerContactPhoneTypeId
)
left outer join ARCCustomerContactPhoneNumber as FaxPhone on
(
FaxPhone.ARCCustomerContactFid = ARCCustomerContact.ARCCustomerContactId and
FaxPhone.ARCCustomerContactPhoneTypeFid = FaxPhoneType.ARCCustomerContactPhoneTypeId
)
left outer join ARCCustomerContactAddress on
(
ARCCustomerContactAddress.ARCCustomerContactFid = ARCCustomerContact.ARCCustomerContactId and
ARCCustomerContactAddress.AddressTypeFid = AddressType.AddressTypeID
)
left outer join CountryCodeStandard on ( CountryCodeStandard.CountryCodeStandardID = ARCCustomerContactAddress.CountryCodeStandardFid )
where AccountingCustomer.CustomerNumber = @inCustomerNumber
order by ARCCustomerContact.AccountingCustomerFid,
ARCCustomerContact.ARCCustomerContactId
end
GO
GRANT EXECUTE ON [dbo].[GetARCCustomerContacts_XLedger] TO [MssExec]
GO