[SOLVED] Validate a input from MySQL

What am I doing wrong?
Whith this I takes the incoming number and uses that against
a MySQL database. Sometimes I have a value in the "number_owner"
field and sometimes the value is in the “nickname” field.

Value example.
in the “number_owner” field: Robert Andersson
or in the “nickname” field: The big guy from sweden!

Next I want to use the value in the “number_owner” field if there is
any, if not use the “nickname” value instead, even if it is NULL!

But none of the below pri 11 works for me!

exten => s,1,Wait(0.3)
exten => s,2,Set(CALLERID=${CALLERID(num)})
exten => s,3,GotoIf($["${CALLERID}" = “”]?1003,1)
exten => s,4,MYSQL(Connect connid ${CID2DB_DB_HOST} ${CID2DB_DB_USER} ${CID2DB_DB_USER_PWD} ${CID2DB_DB_TEST})
exten => s,5,GotoIf($["${connid}" = “”]?db-error,1)
exten => s,6,MYSQL(Query resultid ${connid} SELECT\ number_owner,nickname,salesman\ FROM\ person\ WHERE\ searched_number=’${CALLERID}’)
exten => s,7,MYSQL(Fetch fetchid ${resultid} result_number_owner result_nickname result_salesman)
exten => s,8,MYSQL(Clear ${resultid})
exten => s,9,MYSQL(Disconnect ${connid})
exten => s,10,NoOp(Result number_owner = ${result_number_owner} - nickname = ${result_nickname} - salesman = ${result_salesman})

;exten => s,11,GotoIf($[“foo${result_number_owner}” != “foo”]?name-ok,1:nickname-ok,1)
;exten => s,11,GotoIf($["${result_number_owner}" != “”]?name-ok,1:nickname-ok,1)
;exten => s,11,GotoIf($[${LEN(${result_number_owner})} > 0]?name-ok,1:nickname-ok,1)
;exten => s,11,GotoIf($["${result_number_owner}"]?name-ok,1:nickname-ok,1)

exten => name-ok,1,NoOp(Name is used from the “number_owner” field!)
exten => name-ok,2,Set(CALLERID(all)=${result_number_owner} <${CALLERID(num)}>)
exten => name-ok,3,Dial(SIP/5507,tTrKk)
exten => name-ok,4,Hangup()

exten => nickname-ok,1,NoOp(Name is used from the “nickname” field!)
exten => nickname-ok,2,Set(CALLERID(all)=${result_nickname} <${CALLERID(num)}>)
exten => nickname-ok,3,Dial(SIP/5507,tTrKk)
exten => nickname-ok,4,Hangup()

exten => db-error,1,NoOp(Could not connect to the database!)
exten => db-error,2,Hangup()

exten => h,1,Hangup()
exten => i,1,Hangup()[/code]

Maybe try letting the database do the work for you instead of trying to do it in the dialplan. For Example:

Thanks davevg!

I got it to work with your select!

I also found out that the GotoIf line worked better like this:

instead of:

But manny thanks for your help!