String formatting for queries