How to Download IBM i SQL Results As CSV

  • Home
  • /
  • Blog
  • /
  • How to Download IBM i SQL Results As CSV

March 18, 2022

How to Download IBM i SQL Results As CSV

I had to run a rather interesting SQL statement to download journal information:

select entry_timestamp,
 journal_code,
 journal_entry_type,
 job_name,
 job_user,
 job_number,
 substr(object, 1, 10),
 substr(object, 11, 10),
 substr(object, 21, 10),
 program_name,
 cast(entry_data as char(2000)),
 sequence_number
 from table ( display_journal('JRNLIBNAME','JOURNALNAME', journal_codes => 'R', object_library => 'LIBRARYNAME', object_name => 'FILENAME', object_member => 'MEMBERNAME', object_objtype => '*FILE') 
 ) as x
-- WHERE SUBSTR(CHAR(ENTRY_TIMESTAMP),1,10) = :CheckDate
order by sequence_number;

What does this do?

Essentially, this SQL snippet retrieves journal entry information for the given journal and the file that is journaled.

Running this in the IBM i ACS SQL script explorer gives you the results in a nice spreadsheet friendly format:

The trouble is – you cannot download those results to a spreadsheet by default because it only loads a page at a time. You could sit and press PAGE DOWN… PAGE DOWN… PAGE DOWN… ad infinitum

Or you can turn on ACS’s Spreadsheet download ability in a couple of easy steps.

First, load all the SQL results into the results’ area, ready for download.

Enable the Spreadsheet download function

Goto PREFERENCES, then enable saving of results using scrollable cursors

Stop and restart the SQL tools - 
which means CLOSE THE WINDOW ;)

Now you have restarted the SQL Explorer, you can run the SQL command again, and you will now see a new download option under your RIGHT CLICK menu.


By the Way – By default, the screen only shows a sample of the file data… but you can click the little box in the bottom right to retrieve all data to the screen, so you can view before download. When you click download, all the data will be retrieved anyway – but this little click is useful, so you can see what you are getting before you get it.

Hover over this, and it says “retrieve all rows”

view all data with IBM i SQL Tool
IBM i SQL Tool showing ALL DATA

Right Click inside the results, and you will see a new menu option:

SAVE RESULTS – as a spreadsheet

Download those results as an Excel Spreadsheet!

Which will look something like this.

ba-da-sql-bing

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits.

Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day.

Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

  • You don’t have to perform the extra step of retrieving all rows. If you right-click and save the data, all rows will be retrieved automatically.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Subscribe NOW
    7-day free trial

    Take This Course with ALL ACCESS

    Unlock your Learning Potential with instant access to every course and all new courses as they are released.
     [ For Serious Software Developers only ]

    IBM i Training For Technology Experts

    New!

    Successfully Work Remote 

     $ 129.00  $59.00

    By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely

    >