views:

48

answers:

2

Currently I'm trying to automatically generate a create script for all my SQL jobs of a MS SQL2005 Server.

Does anyone know a good TSQL statement or a simple program for this?

A: 

I maintain files of sql for each table then use cygwin to run a shell script that cats them together then run it on the server.

#!/bin/bash
# Please add new creation scripts and meta data scripts to the script below.
# To be able to run this script don't forget to chmod 744 it.
# Make sure the create script are saved using the ANSI encoding and not unicode etc.

master_script="create_all.sql"
#path="C:\\"

#cd $path

cat *.sql >$master_script

notepad $master_script

#rm $master_script
Mr Shoubs
I think you misunderstood the question, I'm not looking for a method to execute the script, but I'm looking for a script that generate the create statements of all my sql jobs, this by a stored procedure that I can trigger with an osql statement. I need this to backup my sql jobs as a script.
freggel
Bit harsh that I get -1 when your question isn't particularly clear. - it sounds like you DON'T have the sql tables already created and expect the to magically appear
Mr Shoubs
A: 

After some further investigation I found a good script that did the job Generate-Scripts-for-SQL-Server-Objects

The code below is what I needed:

DECLARE @object int
exec sp_OACreate 'SQLDMO.SQLServer', @object OUT
exec sp_OASetProperty @object, 'LoginSecure', TRUE
exec sp_OAMethod @object,'Connect(sqltest)'
exec sp_OAMethod @object, 'Jobserver.Jobs().Script()'
exec sp_OADestroy @object

Thanks for the help anyway

freggel