[dbo].[MssWebGetAccountDetails]
CREATE PROCEDURE [dbo].[MssWebGetAccountDetails]
@inAccountID int
AS
BEGIN
SET NOCOUNT ON;
SELECT
AccountFid=Accounts.AccountPriKey,
AccountName=Accounts.AcctName,
AccountLocationCode=Accounts.DefaultLocationCode,
AccountContact=Accounts.Contact,
AccountMemo=Accounts.Note,
AccountAddressId=AccountAddress.AccountAddressID,
AccountAddress1=AccountAddress.Address1,
AccountAddress2=AccountAddress.Address2,
AccountAddress3=AccountAddress.Address3,
AccountCity=AccountAddress.City,
AccountState=AccountAddress.[State],
AccountPostalCode=AccountAddress.PostalCode,
CountryName=IsNull(AddressCountry.CountryName,DefaultCountry.CountryName),
AccountPhoneNumberId=AccountPhoneNumber.AccountPhoneNumberID,
AccountPhoneNumberCountryCode=ISNULL(PhoneCountry.PhoneCountryCode, DefaultCountry.PhoneCountryCode),
AccountPhoneNumberAreaCode=AccountPhoneNumber.AreaCode,
AccountPhoneNumberLocalNumber=AccountPhoneNumber.LocalNumber,
AccountPhoneNumberExtension=AccountPhoneNumber.Extension,
PhoneCountryFid=ISNULL(PhoneCountry.CountryCodeStandardID, DefaultCountry.CountryCodeStandardID)
FROM Accounts
CROSS JOIN dbo.GetDefaultCountry() DefaultCountry
LEFT OUTER JOIN AccountAddress ON AccountAddress.AccountFID = Accounts.AccountPriKey
LEFT OUTER JOIN AccountPhoneNumber ON AccountPhoneNumber.AccountFID = Accounts.AccountPriKey
LEFT OUTER JOIN CountryCodeStandard PhoneCountry ON AccountPhoneNumber.CountryCodeStandardFID = PhoneCountry.CountryCodeStandardID
LEFT OUTER JOIN CountryCodeStandard AddressCountry ON AccountAddress.CountryCodeStandardFID = AddressCountry.CountryCodeStandardID
WHERE
Accounts.AccountPriKey=@inAccountID
END
GO
GRANT EXECUTE ON [dbo].[MssWebGetAccountDetails] TO [MssExec]
GO