Automate Export Data To Excel Using SQL Script

hello john,

would like to ask help on:

  • how i can insert date stamp on the exported file output, e.g. "c:\temp\xxx."date exported".xlsx"?
  • this is to prevent from overwriting existing files in same folder.
  • in my dataset tab, i want to get only the current records on the table dynamically, e.g.
    "select * from mytable
    where date="current record's date only here"
  • this is to ensure only the current records minus the old ones that were extracted will be exported.

hope am making sense?

thanks for the help :slight_smile:

where does this value come from? Do you want to enter it manually? Today? Something else?

i have a column in the table for the latest record so would want only to export that latest record's date, e.g. column named like "current_date_record"

what i meant was whenever a cron job successfully completes, it stamps the current date on the table (having this column) so we would know it's the latest record.

so you want to find max value in that column and just export that one row (or rows with the same date)? And use that date...whatever it is....in your filename? or just use current timestamp in filename?

to export rows with the latest timestamp, make your sql like this:

select * 
from mytable
where timestamp_column = (select max(timestamp_column) from mytable)

For current date stamp in filename, do this:
image

1 Like

Thank you so much @JohnDorlon, exactly what i need and it's both: I need the output filename to have the current date of the latest record and export only that latest record in excel so you answered them both :wink::+1:

One last question please?

I want to automate this task & I understand that I just need to right-click & input necessary info to schedule it, including username/password so my question is: what kind of account or user privilege is needed to run it on schedule? Is there a special privilege the account am using on the DB needs for this or it will have to be a different account to execute the scheduled task?

(Note: am using Toad for Oracle v.10.5 and my output file just needs to be stored on my local system)

Again, thanks for the much-appreciated help.

The database user will be whatever you use when you create the action in Toad. No special privs there.

I'm not an expert on scheduling, but I think the only thing that you might need to be aware of is some windows accounts might not be able to run scheduled items when you are not logged into windows. Tagging @jbowman to correct me if I'm wrong.

Edit: Toad 10.5 is really old. I'm not sure if the %DATEFILE% trick is going to work in that version. Fingers crossed.

1 Like

This is noted @JohnDorlon, will try to check these then to see what works. Paging @jbowman to help out please?

Wrt my old Toad, had the latest version before but downgraded to this version since am unable to fix compatibility issues with some of my system's tools.

Thanks a ton :+1:

Hi @jbowman, @JohnDorlon,

Just an update:
the %datefile% works and adds the date on the filename output, @JohnDorlon :+1:

Now I input the username and password to automate the task in Automation Designer but clicking "Next", I encountered an error with the ff. details (Please note I omitted some info (like Computer details and Network for security reasons):

EurekaLog 6.0.22

Application:
-------------------------------------------------------

  • 1.1 Start Date : Fri, 7 Feb 2020 17:40:05 +0800 *

  • 1.2 Name/Description: Toad.exe - (Toad for Oracle) *

  • 1.3 Version Number : 10.5.1.3 *

  • 1.4 Parameters : *

  • 1.5 Compilation Date: Wed, 12 May 2010 00:21:33 +0800 *

  • 1.6 Up Time : 3 hours, 32 minutes, 49 seconds *

  • Exception: *

  • ---------------------------------------------------- *

  • 2.1 Date : Fri, 7 Feb 2020 21:12:55 +0800 *

  • 2.2 Address : 00BAADCC *

  • 2.3 Module Name : Toad.exe - (Toad for Oracle) *

  • 2.4 Module Version: 10.5.1.3 *

  • 2.5 Type : EOleException *

  • 2.6 Message : (23,8):UserId:. *

  • 2.7 ID : C657 *

  • 2.8 Count : 1 *

  • 2.9 Status : New *

  • 2.10 Note : *

  • User: *

  • ------------------------------------------------------- *

  • 3.1 ID : Leslie.Matura *

  • 3.2 Name : *

  • 3.3 Email : *

  • 3.4 Company : *

  • 3.5 Privileges: SeShutdownPrivilege - OFF *

  •               SeChangeNotifyPrivilege         - ON *
    
  •               SeUndockPrivilege               - OFF *
    
  •               SeIncreaseWorkingSetPrivilege   - OFF *
    
  •               SeTimeZonePrivilege             - OFF *
    
  • Active Controls: *

  • ------------------------------------------------------- *

  • 4.1 Form Class : Ghost *

  • 4.2 Form Text : Schedule Toad App (Not Responding) *

  • 4.3 Control Class: TButton *

  • 4.4 Control Text : *

  • Computer: *

  • ------------------------------------------------------------------------------------ *

  • 5.1 Name : XXXX-X-99999 *

  • 5.2 Total Memory : 8039 Mb *

  • 5.3 Free Memory : 2759 Mb *

  • 5.4 Total Disk : 237.37 Gb *

  • 5.5 Free Disk : 51.98 Gb *

  • 5.6 System Up Time: 3 hours, 57 minutes, 24 seconds *

  • 5.7 Processor : Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz *

  • 5.8 Display Mode : 1280 x 720, 32 bit *

  • 5.9 Display DPI : 96 *

  • 5.10 Video Card : Intel(R) UHD Graphics 620 (driver 23.20.16.4877 - RAM 1024 MB) *

  • 5.11 Printer : RICOH PCL6 UniversalDriver V4.8 (driver 3.7.43.4) *

  • Operating System: *

  • ---------------------------------------------- *

  • 6.1 Type : Microsoft Windows 6.2 (64 bit) *

  • 6.2 Build # : 9200 *

  • 6.3 Update : *

  • 6.4 Language: English *

  • 6.5 Charset : 0 *

  • Network: *

  • --------------------------------------------------------------------- *

  • 7.1 IP Address: 000.000.000.000 - 999.999.999.999 - 000.000.000.000 *

  • 7.2 Submask : 000.000.000.000 - 999.999.999.999 - 000.000.000.000 *

  • 7.3 Gateway : 000.000.000.000 - 999.999.999.999 - 000.000.000.000 *

  • 7.4 DNS 1 : 000.000.000.000 - 999.999.999.999 - 000.000.000.000 *

  • 7.5 DNS 2 : 000.000.000.000 - 999.999.999.999 - 000.000.000.000 *

  • 7.6 DHCP : ON - ON - ON*

I used the DB account and "run with connections" setup but this error still happens. Could you once more help and advise?

Again, thanks in advance.

Hi Leslie,

Sorry, I missed the tagging in the message yesterday afternoon...

what kind of account or user privilege is needed to run it on schedule? Is there a special privilege the account am using on the DB needs for this or it will have to be a different account to execute the scheduled task?

When scheduling a task to run from the Automation Designer, the username and password you'll need to enter is the Windows account for your computer, not the username and password for your database connection. Toad will create a task in the Windows Task Scheduler that will launch Toad and then log into whatever database you've configured for the App in order to do the work. As John mentioned, if you're trying to use a different account other than your own, make sure it has the ability to run scheduled tasks within Windows.

Based on your Eurekalog that you've attached, I'm not entirely sure why you're getting that error. I do see where there's an EOleException error, but I'm not seeing any kind of call stack to show where that error may be happening. Are you using the correct username and password (Windows one) before clicking the "Next" button?

-John

1 Like

Hey Leslie,

Another thing, as John mentioned and your Eurekalog shows, Toad 10.5 is a very old release that dates back to April 2010. Back then, we were using a third-party component to perform all our task scheduling which really only supported Task Scheduler 1.0 (compatible primarily with Windows XP, Windows Server 2003, and earlier).

If you're trying to use that version of Toad on a newer operating system (i.e. Windows 7+), Task Scheduling from Toad may not work correctly as I don't believe Task Scheduler 1.0 is supported on newer versions of Windows. For that, you'll probably need a newer version of Toad for Oracle. Toad 12.0, I believe, was the first version to support the Task Scheduler 2.0 interfaces.

-John

1 Like

hello @jbowman,

thanks for further guiding me. that is where my mistake is as am using DB credentials instead of windows account. i will try that and see from there; will also update here.

hmm, i guess an upgrade is really called for.

thanks so much once more!