DTS: execute dts package in SQL Agent

DECLARE @cmd        NVARCHAR(4000)
SET @cmd = N'dtsrun /Smy_server /Nmy_dts_package /E'

---------------------------------------------------------------------
DECLARE @outputs    TABLE 
                        (
                            row_num     INT     IDENTITY(0, 1),
                            output NVARCHAR(MAX)
                        )
DECLARE @rc         INT
DECLARE @err_msg    NVARCHAR(MAX)

INSERT INTO @outputs
    EXEC @rc = xp_cmdshell @cmd

IF @rc != 0
BEGIN
    SET @err_msg = ''
    
    SELECT @err_msg = @err_msg + NCHAR(13) + NCHAR(10) + ISNULL(output, '')
    FROM @outputs
    ORDER BY row_num
    
    RAISERROR (@err_msg, 16, 1)
END
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s