
[dbo].[GetCustomerPhone1AreaCodeLocalNbrExt_Legacy]
CREATE PROCEDURE [dbo].[GetCustomerPhone1AreaCodeLocalNbrExt_Legacy]
@inCustomerNumber varchar(15),
@inCustomerAddressCode varchar(15)
as
set nocount on
declare @theCustomerPhone1 char(21)
if( isnull( @inCustomerAddressCode, '' ) = '' )
begin
select
@theCustomerPhone1 = RM00101.Phone1
from RM00101_Synonym as RM00101
where RM00101.CUSTNMBR = convert( varchar(15), @inCustomerNumber )
end
else
begin
select
@theCustomerPhone1 = RM00102.Phone1
from RM00102_Synonym as RM00102
where RM00102.CUSTNMBR = convert( varchar(15), @inCustomerNumber ) and
RM00102.ADRSCODE = convert( varchar(15), @inCustomerAddressCode )
end
select
AreaCode = case
when rtrim( @theCustomerPhone1 ) = '' then null
when substring( @theCustomerPhone1, 1, 3 ) = '000' then null
else substring( @theCustomerPhone1, 1, 3 )
end,
LocalNumber = case
when rtrim( @theCustomerPhone1 ) = '' then null
when substring( @theCustomerPhone1, 1, 3 ) = '000' then null
else substring( @theCustomerPhone1, 4, 3 ) + '-' + substring( @theCustomerPhone1, 7, 4 )
end,
Extension = case
when rtrim( @theCustomerPhone1 ) = '' then null
when substring( @theCustomerPhone1, 1, 3 ) = '000' then null
when rtrim( substring( @theCustomerPhone1, 11, 10 ) ) in ( '0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000', '0000000000' ) then null
else rtrim( substring( @theCustomerPhone1, 11, 10 ) )
end
GO
GRANT EXECUTE ON [dbo].[GetCustomerPhone1AreaCodeLocalNbrExt_Legacy] TO [MssExec]
GO