Thursday, October 3, 2013

SQL Agent Job Logging To Job History Using TSQL

Simple! Use a print statement! Try it! In SQL Server Management Studio (SSMS), in Object Explorer, right click the JOBS folder and click NEW JOB name it TEST click STEPS on the left hand pane click the NEW button name the step TEST STEP make sure the type is Transact-SQL script(TSQL) database can be anything, master is fine. in the big COMMAND box type: Print 'test test test' click OK twice and run the job Right click the job and click VIEW HISTORY click the + to open the list of steps, click on step on and look in the grey pane at the bottom for the details. It will look something like this:
Message Executed as user: sqluser. test test test [SQLSTATE 01000] (Message 0). The step succeeded.
that bolded text is your message! ta da!

No comments: