Create pivot with a grand totals column in a scheduled job

Hello, I want to schedule a job to create a pivot table from a SQL statement. For now, I can use the SQL statment and export the results in a .csv format only. Could you help please ? Thank you