Exporting SQL Database data to Excel?

Is there a way to export data from a SQL database without creating a report?

I know how to create a report and populate with data from my SQL database and once the report is generated you can export to excel and this works great. But I have an odd project where I don't really have a need to create the report but I would like to just export specific data from the database.

Any suggestion will be helpful.

system.db.runQuery + system.dataset.toExcel?

Thanks Kevin, so does that actually create a dataset and then exports that to excel? Could you possibly provide a usage example?

This is an example for a perspective button to download a dataset from my meter data:

def runAction(self, event):
	params = {'start': self.getSibling("StartDate").props.value, 'end': self.getSibling("EndDate").props.value}
	results = system.db.runNamedQuery(system.project.getProjectName(),"MeterData", params)
	spreadsheet = system.dataset.toExcel(True,[results])
	system.perspective.download("Meter_Data_Raw.xlsx", spreadsheet)
3 Likes