Local PivotTableSQL implementation - the original is missing some stuff
and was not updated for a longer while...