I have the following query, and it's working fine, returning each unique Voucher number and the days it took to pay it:SELECT DISTINCT APLINH.Vouchernumber, COALESCE((SELECT APTRAN.Documentdate from PFWEASLEY.APTRAN APTRAN WHERE APTRAN.Transactiontype = 'P' and APTRAN.Applyto = APLINH.Vouchernumber), (SELECT APTRANH.Documentdate from PFWEASLEY.APTRANH APTRANH WHERE APTRANH.Transactiontype = 'P' and APTRANH.Applyto = APLINH.Vouchernumber)) - APLINH.Documentdate AS Days2PayFROM PFWEASLEY.APLINH APLINHWHERE (APLINH.Vendorkey Like 'E%') AND (APLINH.Acct<>'115100000000') AND (APLINH.Documentdate Between {d '2010-01-01'} And {d '2010-01-31'})I'm trying to turn it into a subquery so I can get a count of the number of vouchers for each 'days to pay'.I tried:Select Days2Pay, Count(*)FROM(SELECT DISTINCT APLINH.Vouchernumber, COALESCE((SELECT APTRAN.Documentdate from PFWEASLEY.APTRAN APTRAN WHERE APTRAN.Transactiontype = 'P' and APTRAN.Applyto = APLINH.Vouchernumber), (SELECT APTRANH.Documentdate from PFWEASLEY.APTRANH APTRANH WHERE APTRANH.Transactiontype = 'P' and APTRANH.Applyto = APLINH.Vouchernumber)) - APLINH.Documentdate AS Days2PayFROM PFWEASLEY.APLINH APLINHWHERE (APLINH.Vendorkey Like 'E%') AND (APLINH.Acct<>'115100000000') AND (APLINH.Documentdate Between {d '2010-01-01'} And {d '2010-01-31'}))GROUP BY Days2PayBut I'm getting a syntax error with no hint of where my code is wrong. I'm working in Excel's query builder. Any ideas?