Hello @robayzma,
I just tried reproducing the dynamic segment in a query, I do have an SQL error.
I think the reason is that the expression $long(vars/@recCount) can't be applied here since there are no inbound transition to the query.
If your need is to have the segment named with the count resulting from the query, you can add an enrichment after the query and put your expression there :

Outbound transition from the query :

Enrichment with dynamic segment code :

Outbound transition from the enrichment :
