I have these two tables in the bank
cadcha (Cadastro de chamadas)
cadram(Cadastroderamal)
Allconnectionsmadetoacertaincompanywillbesavedinthistablecadcha
.Thedestinationextensionfieldistheextensionthatansweredormadethisconnection.Ialsohaveasecondtable,calledcadram
,wheretheextensionrecordsareperformedmanually,andthesystemreportsaregeneratedfromthiscadramtable.Iwouldliketoimplementaprocedurethat,whentriggered,wouldregistertheextensionsfoundinthebranchnamefieldofthetagtableinthecadramtable(Obviouslyextensionsthathavenotyethasregistered).Example:Wehavethereinthetabletheramalorigem4554,butinthecadramtablewedonothavethisextensionyet.Iwouldliketheproceduretodothis.
WhatI'veachievedsofar:
SELECTthatreturnsallextensionsofconnectionsthathavenotyetbeenregistered:
SELECTDISTINCT(RAMALDESTINO)FROMCADCHAWHERERAMALDESTINONOTIN(SELECTRAMCODFROMCADRAM)
Scopeoftheprocedure,whichisthepartwhereIcouldnotgoforward:Note:Infirebirdprocedures,isitnecessarytopassonevalueperparameterandreturnsomething?
CREATEPROCEDURESP_CADRAM_AUTOMATICO(testeVARCHAR(1))RETURNS(EXCEPTION"Procedure Acionada"
)
AS
BEGIN
FOR
SELECT DISTINCT (RAMALDESTINO)
FROM CADCHA
WHERE RAMALDESTINO
NOT IN
(SELECT RAMCOD FROM CADRAM)
DO
BEGIN
INSERT INTO CADCHA (RAMCOD, RAMDES) VALUES (RAMALDESTINO, 'RAMAL');
END
END
Enforcing: I need the procedure to register the extensions in the table cadram automatically for me, using as base the table of connections (cadcha) in the branch field.