Distinction between SIP and DID Forwarding

Hallo Friends!

I have an parallel ISDN connection, i. e. inbound calls should came in only in DID. Asterisk stands first and then the Analogue Telephone.

I’m wondering how should PBX be configured, so that Asterisk checks (if available) if a SIP Number exists (as extension from Asterisk) and if not, Asterisk should forward the DID at the Analogue Telephone.

Would try to explain again: if dialed 555555/222, we get in only 222. Now Asterisk should check if an SIP Client with extensions 222 exists. If there is such a SIP extension, it should connect. If such an extensions doesn’t exist, Asterisk should forward the call to the Analogue Phone (Reception).

I heard that this problem can be solved only through a Script. Has anybody such a script that can share with me?

Thanks in advance,

buzuku