SET QUOTED_IDENTIFIER OFF
GO
CREATE view [dbo].[AgentAddresses]
(
AgentFID,
Address1,
Address2,
Address3,
Address,
City,
State,
Country,
CountryCodeStandardFID,
PostalCode
)
as
select
AgentFID = Agent.AgentPriKey,
AgentAddress.Address1,
AgentAddress.Address2,
AgentAddress.Address3,
Address = dbo.BuildAddressFromAddressParts( AgentAddress.Address1, AgentAddress.Address2, AgentAddress.Address3 ),
City = AgentAddress.City,
State = AgentAddress.State,
Country = CountryCodeStandard.CountryName,
CountryCodeStandardFID = AgentAddress.CountryCodeStandardFID,
PostalCode = AgentAddress.PostalCode
from Agent
left outer join AddressType on AddressType.TypeName = 'Main'
left outer join AgentAddress on
(
AgentAddress.AgentFID = Agent.AgentPriKey and
AgentAddress.AddressTypeFID = AddressType.AddressTypeID
)
left outer join CountryCodeStandard on CountryCodeStandard.CountryCodeStandardID = AgentAddress.CountryCodeStandardFID
GO
GRANT SELECT ON [dbo].[AgentAddresses] TO [MssExec]
GRANT INSERT ON [dbo].[AgentAddresses] TO [MssExec]
GRANT DELETE ON [dbo].[AgentAddresses] TO [MssExec]
GRANT UPDATE ON [dbo].[AgentAddresses] TO [MssExec]
GO