Running an SQL Script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Running an SQL Script

Post by winstein » Thu Jul 16, 2015 8:20 am

What I want to do currently, is to use DBExec to run a script from another file.

I did use the ReadFile command to do it, since that's one way in extracting data. The problem is, as I have encountered, when comments are added into the mix. Essentially, based on my observation, comments are not skipped.

What is the best way around this problem?
PPQ

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Running an SQL Script

Post by Marcus Tettmar » Thu Jul 16, 2015 10:50 am

I'm not really sure I understand the question. DBExec is for executing SQL statements like INSERT and UPDATE statements, not for running other script files. Maybe you can explain what you are wanting to do.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Re: Running an SQL Script

Post by winstein » Mon Aug 03, 2015 1:59 am

What I am attempting to do is that basically, I have an SQL file that I want to run in Macro Scheduler, but when I convert the file's contents into a Macro Scheduler script to run this file, there were some problems that prevented it from being run fully. Essentially what I want to do is:

1) Have an SQL file (.sql) with script ready. Specifically, I am putting new things into an empty database.
2) Copy the SQL File's contents into a string.
3) Use said string in Macro Scheduler's DBExec function

The problem is that, certain types of keywords might not be compatible with DBExec, such as GO.
PPQ

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Running an SQL Script

Post by Marcus Tettmar » Tue Aug 04, 2015 9:03 am

This is going to be down to the database type and their ODBC/ADO driver that you are using. You would need to consult their documentation. DBExec in Macro Scheduler is dumb. Macro Scheduler does zero processing. DBExec is simply a conduit through to the database driver you are using. The SQL string you enter is simply passed on to the driver which passes it to the database server. We have no control over the content of that. The syntax is decided by the database vendor. It is possible I guess that their driver supports less than what can be achieved within the database software itself, but I have no idea.

If you tell us which database flavour this is and which driver you are using I *might* be able to help you look up some documentation.

Sorry to sound like I'm passing the buck, but really, that is precisely what DBExec does - it passes the buck on to the driver.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jamball77
Newbie
Posts: 14
Joined: Tue Aug 11, 2015 2:25 pm

Re: Running an SQL Script

Post by Jamball77 » Wed Aug 12, 2015 6:24 pm

//FYI the Database Reference is here:

https://www.mjtnet.com/blog/2008/04/15/ ... functions/

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts