Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 setting a script to run once a week automatically

Author  Topic 

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 14:27:45
how do some of you set a script to run automatically... we are looking to have one of our scripts run once a week at a particular time.

any info to do it through the following:

- in sql query analyzer? (cause this is what the clerks are using to run scripts)

- sql server mgmt studio?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-15 : 14:44:05
You put the script in a job. Are you familiar with setting up SQL Server jobs?

Tara Kizer
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 14:48:28
no i dont, can you give me some reading material?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-15 : 15:01:21
The reading material would be SQL Server Books Online.

To start trying it out, you can go to SQL Server Agent/Jobs in Management Studio.

Tara Kizer
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 15:08:20
perfect thanks... ill sign on to our Mgmt Studio and read up on this.
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 15:41:11
okie dokie... i created a new job within SQL Server Mgmt Studio... Let call it "Field Automation Weekly"... we are currently writing a sql script that will gather data (i might have questions on this later) and select INTO a Table inside of separate database we've created (lets call this script weekly.sql) now double clicking into the Job Properties i see General, Steps, Schedules, Alerts, Notifications, and Targets. before i read up on each, which one should i be concerned with regarding setting it to run "weekly.sql" at 2 AM sunday nights?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-15 : 16:13:31
Schedules is where you set a schedule for the job


Tara Kizer
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 19:18:58
got it! thanks again... i set the schedule... we just have to write the correct script.

we are back to the drawing board regarding an old question i had... how do i write a sql script that will automatically dump and save the data as a "csv" or "txt"... i tried this and it doesnt work...

bcp "SELECT top 10 * FROM employee" queryout c:\temp\contacts.txt -c -T

it returns an error at the queryout part
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 19:40:38
actually okay.. i realize BCP is a COMMAND prompt/line... now if only i can get it to schedule to run the BCP command line in cmd prompt... i was thinking putting it in a .bat file and trying to get it to schedule to run the bat.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-15 : 19:48:56
You need to use the three part naming convention for the object:

bcp "SELECT top 10 * FROM SomeDatabase.SomeOwner.employee" queryout c:\temp\contacts.txt -c -T -t, -r\r\n -SsomeServer

You can schedule command line stuff in a SQL Server job. In the job step, just select Operating System (cmdExec) for the Type. Whatever you can run from a cmd window can be put in a cmdExec job step.

Tara Kizer
Go to Top of Page

racinghart
Starting Member

49 Posts

Posted - 2007-02-15 : 20:16:57
sweet! thanks again, tara... bcp "SELECT top 1 * FROM solomon.field_automation.dbo.all_tasks" queryout c:\temp\contacts.txt -c -T


it worked... i put it under the OS (cmdExec) type.
Go to Top of Page
   

- Advertisement -