Create Sql query from 1c