Caller inputs account number or similar

Well, its not really that trivial to make this work…

Create a dialplan code to ask the users to input a numerical item to look up. PIN number for example.

First lets create some code to ask the customer for their pin number

open up /etc/asterisk/extensions_custom.conf

Go to the bottom of the file and paste this in the code below, but altering the following portions below that are in ALLCAPS that are specific to your situation)

[customerlookup]
exten => s,1,Answer()
exten => s,n,Playback(please-enter-your&pin_number)
exten => s,n,Read(pinnumber,then-press-pound,4,,1,10)

;MYSQL connection - adjust these values to reflect your database logon info
exten => s,n,MYSQL(Connect connid DATABASE_IP SQLUSER SQLPASSWORD DATABASENAME)

;Find the matching column of the pin number, and then pull data  from the column you want
exten => s,n,MYSQL(Query resultid ${connid} select COLUMN_NAME_TO_PULL from TABLENAME where COLUMN_WITH_MATCHING_IVRDATA=${pinnumber})

;pull the matching data (IF any) and store it in the variable "COLUMN_NAME_TO_PULL"
exten => s,n,MYSQL(Fetch fetchid ${resultid} resultfound)

;cleanup connection to database
exten => s,n,MYSQL(Disconnect ${connid})

;If no matching data, system plays "hangup and try again", then it hangs up the phone.
exten => s,n,ExecIf($["${resultfound}"=""]?playback(hangup-try-again))
exten => s,n,ExecIf($["${resultfound}"=""]?HANGUP())

;if the resultfound contains data, the system says "THANK YOU" and then says the value in the variable
exten => s,n,PlayBack(auth-thankyou)
exten => s,n,SayDigits(${resultfound})
exten => s,n,Hangup()

Save those changes

EDIT:
create a “Custom Destination”
Create a destination called
" customerlookup "
and for “Custom Destination” put in
customerlookup,s,1
Save those changes.

Now, create a route or something to call that customer destination. Can use a ring group to point to it or an IVR prompt or inbound route.

Give it a run. System should ask you to input a value, then will query the database for that data and return the result.