Submitted by adam.singer on Fri, 12/20/2013 - 10:04am
Can you provide a small code snippet with comments of how one would generate a downloadable csv file based off of a tlist_sql statement. I want to create a custom page that uses tlist_sql to pull some data and then lets the user download a csv of the data.
babukoot
Wed, 01/01/2014 - 4:45pm
Permalink
Tlist_SQL to CSV Export
Hi,
First thing you need to do is create a file with the extension .csv (like somereport.csv).
Then place the code below:
~[tlist_sql;Select Distinct 'First Name, Last Name, Grade Level, Gender, Ethnicity' as csvtext from students
union all
Select a || ', ' || b ||', ' || c || ', ' || d ||', ' || e as csvtext
from
(Select first_name a, last_name b, grade_level c, gender d, ethnicity e
from students where enroll_status = 0);] ~(csvtext)
[/tlist_sql]
on your original report page, add a link to the file like
Click here to download csv file
Here the || concatenates two strings and ', ' inserts a comma in between two fields. If your query has fields that contain a comma already, (like lastfirst) then csv file may not be a good choice. The advantage of using csv file is that the browser will initiate a download.