First of all you have issue with macros for you query. There are 4 standard ones:
- ##WHERE## Macro substitutes 'WHERE' condition
- ##TOPN## Macro substitutes 'TOP n' clause
- ##ORDERBY## Macro substitutes 'ORDER BY' rule
- ##COLUMNS## Macro substitutes list of columns
Those 4 go into corresponding properties of your web part/widget:
You query should look like
select ##TOPN## *
from customtable_phone_directory
where ##WHERE##
order by ItemCreatedWhen asc
Now you can put your where and top in the properties :
Assuming your macro {% DirectoryCategory %}
resolves correctly it should work