Prepare data error query generation