1answers

Variable in ExecuteSQL?

Is it possible via ExecuteSQL to use a variable like this?

Let (

@sort = INFORMATION::exsqlsort

ExecuteSQL ( " SELECT \"name\" FROM \"TOPICLIST\"

WHERE \"_fk_infoparent_id\" = ?
ORDER BY \"name\" @sort" ;

"";

"";

INFORMATION::_kp_information_id

)

)

Then I would go to a field named INFORMATION::exsqlsort setup as radio button with the choices ASC and DESC.

Chris Johnston

Answers

This is possible, but not using the syntax you're showing.

Let ( [

~sort = Information::executeSQLSortOrder ;

~query =

"SELECT \"name\" FROM \"TopicList\"

WHERE \"id_Information\" = ?

ORDER BY \"name\" "

& ~sort

] ;

ExecuteSQL (

~query ;

"" ;

"" ;

Information::id

)

)

Also, I see you're quoting literal text for your field names. You should not be doing that in production FileMaker code. FileMaker fields get renamed often, and ExecuteSQL queries built like this don't know when fields get renamed, so it's a best practice to wrap references to FileMaker fields in custom functions so the SQL doesn't break. Exactly what's the best way to do this is not exactly a settled question.

Jeremy Bante

Back to questions