To Display query which are currently exceuting from form datasource in Axapta. You just need to user toString method with Querybuilddatasource clase object,
Query q;
QueryBuildDataSource qbds;
;
q = this.query();
qbds = q.dataSourceName("CustTable");
strfmt("%1", qbds.toString());