# Get Automise to run a sql query

**URL:** https://www.finalbuilder.com/forums/t/get-automise-to-run-a-sql-query/4366
**Category:** Discussion
**Created:** [April 13, 2009, 3:23am UTC](https://www.finalbuilder.com/forums/t/get-automise-to-run-a-sql-query/4366 "2009-04-13T03:23:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [April 13, 2009, 3:23am UTC](https://www.finalbuilder.com/forums/t/get-automise-to-run-a-sql-query/4366/1 "2009-04-13T03:23:18Z")

</div>

How can I get automise to run an SQL&nbsp;query?&nbsp; I am wanting to automate this task so that I don't have to physically do it every morning.

Here is an example of the first few lines.

--Verify Trace is Running (if no records returned, trace is not running)

SELECT \* FROM :: fn\_trace\_getinfo(0)

DECLARE @TraceID INT

DECLARE @MaxSize bigint

DECLARE @StopLogTime datetime

&nbsp;

SET @MaxSize = 500

--STEP 1 - Change the Log Stop Time (next day)

SET @StopLogTime = '2008-09-24 22:00:00'

--STEP 2 - Modify the Trace Log File Output Name

EXECUTE sp\_trace\_create @TraceID output,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @options = 2, --//rollover the file when max size is reached

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @tracefile = N'E:\Unapen\Task Centre\SQL Traces\Lock\_Timeout\_Monitor\_20080924', --//trace file name

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @maxfilesize = @MaxSize, --//maximum file size

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @stoptime = @StopLogTime

---

<div class="post-metadata">

### Author: ![paulsamways](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@paulsamways](https://www.finalbuilder.com/forums/u/paulsamways)
#### Post date: [April 17, 2009, 3:17am UTC](https://www.finalbuilder.com/forums/t/get-automise-to-run-a-sql-query/4366/2 "2009-04-17T03:17:50Z")

</div>

Hi,   
  
 You should be able to use the ‘MSSQL Execute SQL’ action to execute the script. You can either choose to save the script as a file and set the action to take the input from that file or you can place the script directly in the action’s ‘Text Query’ field.   
  
 Regards,   
 Paul.
