csv & sql generation now working