9.5 Convert table sequence into CSV format

 

Transform a table sequence into CSV format and separate field values in a record with the comma.
One task is to convert Department table into CSV format and copy it to the system clipboard. Below is Department table:

ID Name Manager
1 Administration 1
2 Finance 4
3 HR 5
4 Marketing 6
5 Production 7

In SPL, A.export() function concatenates members of a table sequence and returns a result as a string. @t option enables generating the title row, and @c option means generating CSV format.
SPL script:

A
1 =connect(“db”)
2 =A1.query@x(“select * from Department”)
3 =A2.export@ct()
4 =clipboard(A3)

A1 Connect to the data source.
A2 Import Department table.
A3 Use A.export() function to concatenate members of A2’s table sequence into a string. @c option enables generating CSV format, and @t option enables to generate the title row.
A4 Copy A3’s string to the system clipboard.

Execution result:
A2:

ID Name Manager
1 Administration 1
2 Finance 4
3 HR 5

A3:

ID,Name,Manager
1,Administration,1
2,Finance,4
3,HR,5
…