====== pears.NetGetEmail ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."NetGetEmail"( in "cpe" char(2),in "recid" char(20) )
returns char(250)
//IQXWeb
begin
declare "rv" char(250);
select first "replace"("phone"."number",'*','') into "rv" from "phone" key join "phonetype" where "phone"."whoid" = "recid" and "phone"."who" = (if "cpe" = 'E' then 'CP' else "cpe" endif)
and "phonetype"."name" = 'E-mail' order by 1 asc;
return("rv")
end /* TEST
call NetTestSetup('');
delete from phone where phoneid like 'test%';
insert into phone (phoneid, phonetypeid, who, whoid, number) values ('Test1',(select top 1 phonetypeid from phonetype where name like 'E-Mail' and contact=1),'CP','TEST','test@test.com');
insert into phone (phoneid, phonetypeid, who, whoid, number) values ('Test2',(select top 1 phonetypeid from phonetype where name like 'E-Mail' and company=1),'C','TEST','test2@test.com');
select NetGetEmail(null,null);
expect;
select NetGetEmail('x','f99');
expect;
select isnull(NetGetEmail('x','TEST'),'empty');
expect empty;
select NetGetEmail('C','x');
expect;
select NetGetEmail('C','TEST');
expect test2@test.com;
select NetGetEmail('E','TEST');
expect test@test.com;
delete from phone where phoneid like 'test%';
*/
/* DOC
2016-08-25 PC tests and document
2020-04-21 JW Rewritten for inlining.
inputs:
cpe - phone.who
recid - phone.whoid
outputs:
rv - return value
tests:
null cpe and null recid
incorrect cpe incorrect recid
incorrect cpe correct recid
correct cpe (not E) incorrect recid
correct cpe (not E) correct recid
correct cpe (E) correct recid
*/