home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / sqlsvr / alpha / instdist.sql < prev    next >
Encoding:
Text File  |  1995-12-15  |  98.6 KB  |  3,586 lines

  1.  
  2. /***********
  3. InstDist.SQL   1995/12/11 19:34
  4. ***********/
  5.  
  6. go
  7. use master
  8. go
  9.  
  10. declare @special_db_name varchar(30)
  11. select  @special_db_name = 'distribution'
  12.  
  13. if not exists (select * from sysdatabases where name=@special_db_name)
  14.     begin
  15.     raiserror('No error but, db=''%s'' does NOT exist, so this ISQL run will terminate now.'
  16.                  ,1,127 ,@special_db_name)
  17.     end
  18. go
  19.  
  20. declare @special_db_name varchar(30)
  21. select  @special_db_name = 'distribution'
  22.  
  23. if not exists (select * from sysdatabases where name=@special_db_name)
  24.     begin
  25.     raiserror('Minor error, because you should not see this message!  Harshly killing spid.'
  26.                  ,22,127) with log
  27.     end
  28. go
  29.  
  30. ------------------------------------------------------
  31. go
  32. use distribution
  33. go
  34.  
  35. dump transaction distribution with no_log
  36. go
  37.  
  38. select 'At top, db_name()=',db_name()
  39.  
  40. go
  41. EXEC sp_configure 'allow updates', 1
  42. GO
  43. reconfigure with override
  44. GO
  45.  
  46. /****************************************************************************/
  47. PRINT ''
  48. PRINT 'Create distribution tables'
  49. PRINT ''
  50. /****************************************************************************/
  51. EXEC sp_create_distribution_tables
  52. GO
  53.  
  54. /****************************************************************************/
  55. PRINT ''
  56. PRINT 'Dropping all distribution stored procedures'
  57. PRINT ''
  58. /****************************************************************************/
  59. IF EXISTS (select * from sysobjects where
  60.     name = 'sp_MSdistribution_cleanup' and type = 'P')
  61.        DROP PROCEDURE sp_MSdistribution_cleanup
  62. GO
  63.  
  64. IF EXISTS (select * from sysobjects where
  65.    name = 'sp_replcleanup' and type = 'P')
  66.       DROP PROCEDURE sp_replcleanup
  67. GO
  68.  
  69. IF EXISTS (SELECT * FROM sysobjects WHERE
  70.    name = 'sp_MSadd_job' and type = 'P')
  71.       DROP PROCEDURE sp_MSadd_job
  72. GO    
  73.  
  74. IF EXISTS (SELECT * FROM sysobjects WHERE
  75.    name = 'sp_MSadd_job_command' and type = 'P')
  76.       DROP PROCEDURE sp_MSadd_job_command
  77. GO    
  78.  
  79. IF EXISTS (SELECT * FROM sysobjects WHERE
  80.    name = 'sp_MSsubscriber_status' and type = 'P')
  81.       DROP PROCEDURE sp_MSsubscriber_status
  82. GO
  83.  
  84. IF EXISTS (SELECT * FROM sysobjects WHERE
  85.    name = 'sp_MSadd_subscription' and type = 'P')
  86.       DROP PROCEDURE sp_MSadd_subscription
  87. GO    
  88.  
  89. IF EXISTS (SELECT * FROM sysobjects WHERE
  90.    name = 'sp_MSdrop_subscription' and type = 'P')
  91.       DROP PROCEDURE sp_MSdrop_subscription
  92. GO    
  93.  
  94. IF EXISTS (SELECT * FROM sysobjects WHERE
  95.     name = 'sp_MSupdate_job' and type = 'P')
  96.     DROP PROCEDURE sp_MSupdate_job
  97. GO    
  98.  
  99. IF EXISTS (SELECT * FROM sysobjects WHERE
  100.     name = 'sp_MSupdate_subscription' and type = 'P')
  101.        DROP PROCEDURE sp_MSupdate_subscription
  102. GO    
  103.  
  104. IF EXISTS (SELECT * FROM sysobjects WHERE
  105.     name = 'sp_MSadd_subscriber_job' and type = 'P')
  106.        DROP PROCEDURE sp_MSadd_subscriber_job
  107. GO    
  108.  
  109. IF EXISTS (SELECT * FROM sysobjects WHERE
  110.     name = 'sp_MSget_subscriber_jobs' and type = 'P')
  111.        DROP PROCEDURE sp_MSget_subscriber_jobs
  112. GO    
  113.  
  114. IF EXISTS (SELECT * FROM sysobjects WHERE
  115.    name = 'sp_MSfind_subscriber_job' and type = 'P')
  116.       DROP PROCEDURE sp_MSfind_subscriber_job
  117. GO    
  118.  
  119. IF EXISTS (SELECT * FROM sysobjects WHERE
  120.    name = 'sp_MSget_last_job' and type = 'P')
  121.       DROP PROCEDURE sp_MSget_last_job
  122. GO    
  123.  
  124. IF EXISTS (SELECT * FROM sysobjects WHERE
  125.    name = 'sp_MSget_last_trans' and type = 'P')
  126.       DROP PROCEDURE sp_MSget_last_trans
  127. GO    
  128.  
  129. IF EXISTS (SELECT * FROM sysobjects WHERE
  130.    name = 'sp_MSadd_subscriber_info' and type = 'P')
  131.       DROP PROCEDURE sp_MSadd_subscriber_info
  132. GO    
  133.  
  134. IF EXISTS (SELECT * FROM sysobjects WHERE
  135.    name = 'sp_MSupdate_subscriber_info' and type = 'P')
  136.       DROP PROCEDURE sp_MSupdate_subscriber_info
  137. GO    
  138.  
  139. IF EXISTS (SELECT * FROM sysobjects WHERE
  140.    name = 'sp_MSdrop_subscriber_info' and type = 'P')
  141.       DROP PROCEDURE sp_MSdrop_subscriber_info
  142. GO    
  143.  
  144. IF EXISTS (SELECT * FROM sysobjects WHERE
  145.    name = 'sp_MShelp_subscriber_info' and type = 'P')
  146.       DROP PROCEDURE sp_MShelp_subscriber_info
  147. GO    
  148.  
  149. IF EXISTS (select * from sysobjects where
  150.    name = 'sp_MSkill_job' and type = 'P')
  151.       DROP PROCEDURE sp_MSkill_job
  152. GO
  153.  
  154. IF EXISTS (select * from sysobjects where
  155.    name = 'sp_MSnew_sync' and type = 'P')
  156.       DROP PROCEDURE sp_MSnew_sync
  157. GO
  158.  
  159. IF EXISTS (select * from sysobjects where
  160.    name = 'sp_MSdistribution_counters' and type = 'P')
  161.       DROP PROCEDURE sp_MSdistribution_counters
  162. GO
  163.  
  164. IF EXISTS (select * from sysobjects where
  165.    name = 'sp_MSremove_published_jobs' and type = 'P')
  166.       DROP PROCEDURE sp_MSremove_published_jobs
  167. GO
  168.  
  169. dump transaction distribution with no_log
  170. go
  171.  
  172. /****************************************************************************/
  173. PRINT ''
  174. PRINT 'Creating Stored Procedure:  dbo.sp_MSdistribution_cleanup'
  175. PRINT ''
  176. /****************************************************************************/
  177. GO
  178. CREATE PROCEDURE sp_MSdistribution_cleanup
  179. @publisher_id smallint,
  180. @publisher_db varchar(30),
  181. @subscriber_id smallint,
  182. @subscriber_db varchar(30),
  183. @cutoff_time datetime,
  184. @num_commands int OUTPUT
  185.  
  186. as
  187.    declare @max_cleanup_job int
  188.  
  189.    SET NOCOUNT ON
  190.  
  191.    /*
  192.    ** Delete all subscriber jobs that have been completed and archived for
  193.    ** the subscriber's retention period.
  194.    */
  195.    select @max_cleanup_job = max (job_id) from
  196.       MSsubscriber_status (index = ucMSsubscriber_status) where
  197.       publisher_id = @publisher_id and
  198.       publisher_db = @publisher_db and
  199.       subscriber_id = @subscriber_id and
  200.       subscriber_db = @subscriber_db and
  201.       completion_time < @cutoff_time
  202.    if @@error <> 0
  203.       return (1)
  204.  
  205.    select @num_commands = count(*)
  206.     from MSsubscriber_jobs (index = ucMSsubscriber_jobs) where
  207.          publisher_id = @publisher_id and
  208.          publisher_db = @publisher_db and
  209.     subscriber_id = @subscriber_id and
  210.     subscriber_db = @subscriber_db and
  211.     job_id <= @max_cleanup_job
  212.    if @@error <> 0
  213.       return (1)
  214.  
  215.    delete MSsubscriber_jobs from MSsubscriber_jobs where
  216.          publisher_id = @publisher_id and
  217.          publisher_db = @publisher_db and
  218.     subscriber_id = @subscriber_id and
  219.     subscriber_db = @subscriber_db and
  220.     job_id <= @max_cleanup_job
  221.    if @@error <> 0
  222.       return (1)
  223.  
  224.    /*
  225.    ** Delete all subscriber status that have been around for longer than
  226.    ** the subscriber's retention period. Always leave the last entry for
  227.    ** each distribution process.
  228.    */
  229.    delete MSsubscriber_status from MSsubscriber_status ss1 where
  230.        publisher_id = @publisher_id and
  231.        publisher_db = @publisher_db and
  232.        subscriber_id = @subscriber_id and
  233.        subscriber_db = @subscriber_db and
  234.        job_id < @max_cleanup_job and
  235.        job_id <> (select max(job_id) from
  236.         MSsubscriber_status ss2 (index = ucMSsubscriber_status) where
  237.         ss2.publisher_id = @publisher_id and
  238.         ss2.publisher_db = @publisher_db and
  239.         ss2.subscriber_id = @subscriber_id and
  240.         ss2.subscriber_db = @subscriber_db)
  241.    if @@error <> 0
  242.       return (1)
  243.  
  244. go
  245.  
  246. /* Set category bit to reflect MS objects */
  247. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  248.     name = 'sp_MSdistribution_cleanup'
  249. go
  250.  
  251. /****************************************************************************/
  252. PRINT ''
  253. PRINT 'Creating Stored Procedure:  dbo.sp_replcleanup'
  254. PRINT ''
  255. /****************************************************************************/
  256. GO
  257. CREATE PROCEDURE sp_replcleanup
  258. @publisher varchar(30),
  259. @subscriber varchar(30),
  260. @retention int
  261.  
  262. as
  263.    declare @publisher_id smallint
  264.    declare @publisher_db varchar (30)
  265.    declare @subscriber_id smallint
  266.    declare @subscriber_db varchar (30)
  267.    declare @cutoff_time datetime
  268.    declare @retcode int
  269.    declare @novalue int
  270.    declare @num_commands int
  271.    declare @total_commands int
  272.    declare @max_cleanup_job int
  273.    declare @delcmd varchar (255)
  274.    declare @job_command varchar (255)
  275.    declare @file varchar (255)
  276.    declare @table varchar (255)
  277.  
  278.  
  279.    SET NOCOUNT ON
  280.  
  281.    select @cutoff_time = dateadd(hour, -@retention, getdate())
  282.    select @total_commands = 0
  283.  
  284.    /*
  285.    ** Make sure the publisher is valid.
  286.    */
  287.    select @publisher_id = srvid from master..sysservers where
  288.        srvname = @publisher
  289.    if @publisher_id is NULL
  290.    begin
  291.       RAISERROR(14048, 16, -1, @publisher)
  292.       return (1)
  293.    end
  294.  
  295.    /*
  296.    ** Make sure the subscriber is valid.
  297.    */
  298.    select @subscriber_id = srvid from master..sysservers where
  299.        srvname = @subscriber
  300.    if @subscriber_id is NULL
  301.    begin
  302.       RAISERROR(14048, 16, -1, @subscriber)
  303.       return (1)
  304.    end
  305.  
  306.    begin transaction sp_replcleanup
  307.  
  308.    /* To prevent deadlocking with running replication, get an exclusive
  309.    ** lock on distribution tables.
  310.    */
  311.    select @novalue = job_id from MSjobs (TABLOCKX HOLDLOCK) where 1=2
  312.    select @novalue = job_id from MSjob_commands (TABLOCKX HOLDLOCK) where 1=2
  313.    select @novalue = job_id from MSsubscriber_jobs (TABLOCKX HOLDLOCK) where 1=2
  314.  
  315.    /* Open a cursor to get each publisher/subscriber database pair */
  316.    declare hC cursor for select distinct publisher_db, subscriber_db
  317.       from MSjob_subscriptions
  318.       where publisher_id = @publisher_id for read only
  319.       
  320.    open hC
  321.    fetch hC into @publisher_db, @subscriber_db
  322.    while (@@fetch_status <> -1)
  323.       begin
  324.  
  325.        execute @retcode = sp_MSdistribution_cleanup @publisher_id,
  326.         @publisher_db, @subscriber_id, @subscriber_db, @cutoff_time,
  327.         @num_commands OUTPUT
  328.  
  329.      select 'publisher_db' = @publisher_db,
  330.         'subscriber_db' = @subscriber_db,
  331.         'removed commands' = @num_commands
  332.      if @retcode <> 0
  333.         begin
  334.            close hC
  335.                DEALLOCATE hC
  336.            rollback transaction sp_replcleanup
  337.            return (1)
  338.         end
  339.  
  340.      select @total_commands = @total_commands + @num_commands
  341.  
  342.          fetch hC into @publisher_db, @subscriber_db
  343.       end
  344.    close hC
  345.    DEALLOCATE hC
  346.  
  347.    /* Open a cursor to get each publisher database */
  348.    declare hC2 cursor for select distinct publisher_db from MSjobs
  349.       where publisher_id = @publisher_id for read only
  350.    open hC2
  351.    fetch hC2 into @publisher_db
  352.    while (@@fetch_status <> -1)
  353.       begin
  354.        /*
  355.        ** For each sync command that no longer has a subscriber job delete the
  356.        ** sync file.
  357.        */
  358.        declare hC3 cursor for select jc.command from MSjobs j (index = ucMSjobs),
  359.          MSjob_commands jc (index = ucMSjob_commands) where
  360.          j.publisher_id = @publisher_id and
  361.          j.publisher_db = @publisher_db and
  362.          (j.type = 3 or j.type = 4 or j.type = 5) and
  363.          not exists (select * from MSsubscriber_jobs sj
  364.      (index = ucMSsubscriber_jobs) where
  365.             j.publisher_id = sj.publisher_id and
  366.         j.publisher_db = sj.publisher_db and
  367.         j.job_id = sj.job_id) and
  368.          jc.publisher_id = j.publisher_id and
  369.          jc.publisher_db = j.publisher_db and
  370.          jc.job_id = j.job_id
  371.  
  372.       OPEN hC3
  373.       FETCH hC3 INTO @job_command
  374.       WHILE (@@fetch_status <> -1)
  375.          BEGIN
  376.             EXEC @retcode = master..xp_sscanf @job_command, 'sync -t%s -d%s',
  377.            @value1 = @table output, @value2 =@file output
  378.             IF @retcode <> 0
  379.         begin
  380.            CLOSE hC3
  381.            DEALLOCATE hC3
  382.                return (1)
  383.         end
  384.  
  385.             EXEC @retcode = master..xp_sprintf @string = @delcmd output,
  386.         @format = 'del %s', @value = @file
  387.             IF @retcode <> 0
  388.         begin
  389.            CLOSE hC3
  390.            DEALLOCATE hC3
  391.                return (1)
  392.         end
  393.  
  394.             EXEC master..xp_cmdshell @delcmd
  395.  
  396.             FETCH hC3 INTO @job_command
  397.          END
  398.       CLOSE hC3
  399.       DEALLOCATE hC3
  400.  
  401.       /* Remove all orphaned jobs (no entry in MSsubscriber_jobs) from MSjobs */
  402.       delete MSjobs from MSjobs j where
  403.          j.publisher_id = @publisher_id and
  404.          j.publisher_db = @publisher_db and
  405.          j.job_id not in (select job_id from MSsubscriber_jobs sj (index = ncMSsubscriber_jobs) where
  406.             sj.publisher_id = j.publisher_id and
  407.         sj.publisher_db = j.publisher_db and
  408.         sj.job_id = j.job_id) and
  409.          j.job_id <> (select max(job_id) from MSjobs j (index = ucMSjobs) where
  410.             j.publisher_id = @publisher_id and
  411.             j.publisher_db = @publisher_db and
  412.         j.xactid_page <> 0) and
  413.          j.job_id <> (select max(job_id) from MSjobs j (index = ucMSjobs) where
  414.             j.publisher_id = @publisher_id and
  415.             j.publisher_db = @publisher_db) 
  416.       if @@error <> 0
  417.          begin
  418.             close hC2
  419.             DEALLOCATE hC2
  420.             rollback transaction sp_replcleanup
  421.             return (1)
  422.          end
  423.    
  424.        /* Remove all orphaned command (no entry in MSjobs) from MSjob_commands */
  425.        delete MSjob_commands from MSjob_commands jc where
  426.          jc.publisher_id = @publisher_id and
  427.          jc.publisher_db = @publisher_db and
  428.          jc.job_id not in (select job_id from MSjobs j (index = ucMSjobs) where
  429.             j.publisher_id = jc.publisher_id and
  430.         j.publisher_db = jc.publisher_db and
  431.             j.job_id = jc.job_id)
  432.       if @@error <> 0
  433.          begin
  434.             close hC2
  435.             DEALLOCATE hC2
  436.             rollback transaction sp_replcleanup
  437.             return (1)
  438.          end
  439.  
  440.        fetch hC2 into @publisher_db
  441.       end
  442.    close hC2
  443.    DEALLOCATE hC2
  444.  
  445.    commit transaction sp_replcleanup
  446.  
  447.    RAISERROR(14089, 10, -1, @total_commands, @subscriber)
  448. go
  449.  
  450. /* Set category bit to reflect MS objects */
  451. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  452.     name = 'sp_replcleanup'
  453. go
  454.  
  455. /****************************************************************************/
  456. PRINT ''
  457. PRINT 'Creating Stored Procedure:  dbo.sp_MSadd_job'
  458. PRINT ''
  459. /****************************************************************************/
  460. GO
  461. CREATE PROCEDURE sp_MSadd_job
  462. @publisher_id smallint,
  463. @publisher_db varchar (30),
  464. @job_id int = 0,
  465. @type tinyint = 0,
  466. @xactid_page int = 0,
  467. @xactid_row smallint = 0,
  468. @xactid_ts binary(8) = 0,
  469.  
  470. @job_id01 int = 0,
  471. @xactid_page01 int = NULL,
  472. @xactid_row01 smallint = NULL,
  473. @xactid_ts01 binary(8) = NULL,
  474.  
  475. @job_id02 int = 0,
  476. @xactid_page02 int = NULL,
  477. @xactid_row02 smallint = NULL,
  478. @xactid_ts02 binary(8) = NULL,
  479.  
  480. @job_id03 int = 0,
  481. @xactid_page03 int = NULL,
  482. @xactid_row03 smallint = NULL,
  483. @xactid_ts03 binary(8) = NULL,
  484.  
  485. @job_id04 int = 0,
  486. @xactid_page04 int = NULL,
  487. @xactid_row04 smallint = NULL,
  488. @xactid_ts04 binary(8) = NULL,
  489.  
  490. @job_id05 int = 0,
  491. @xactid_page05 int = NULL,
  492. @xactid_row05 smallint = NULL,
  493. @xactid_ts05 binary(8) = NULL,
  494.  
  495. @job_id06 int = 0,
  496. @xactid_page06 int = NULL,
  497. @xactid_row06 smallint = NULL,
  498. @xactid_ts06 binary(8) = NULL,
  499.  
  500. @job_id07 int = 0,
  501. @xactid_page07 int = NULL,
  502. @xactid_row07 smallint = NULL,
  503. @xactid_ts07 binary(8) = NULL,
  504.  
  505. @job_id08 int = 0,
  506. @xactid_page08 int = NULL,
  507. @xactid_row08 smallint = NULL,
  508. @xactid_ts08 binary(8) = NULL,
  509.  
  510. @job_id09 int = 0,
  511. @xactid_page09 int = NULL,
  512. @xactid_row09 smallint = NULL,
  513. @xactid_ts09 binary(8) = NULL,
  514.  
  515. @job_id10 int = 0,
  516. @xactid_page10 int = NULL,
  517. @xactid_row10 smallint = NULL,
  518. @xactid_ts10 binary(8) = NULL,
  519.  
  520. @job_id11 int = 0,
  521. @xactid_page11 int = NULL,
  522. @xactid_row11 smallint = NULL,
  523. @xactid_ts11 binary(8) = NULL,
  524.  
  525. @job_id12 int = 0,
  526. @xactid_page12 int = NULL,
  527. @xactid_row12 smallint = NULL,
  528. @xactid_ts12 binary(8) = NULL,
  529.  
  530. @job_id13 int = 0,
  531. @xactid_page13 int = NULL,
  532. @xactid_row13 smallint = NULL,
  533. @xactid_ts13 binary(8) = NULL,
  534.  
  535. @job_id14 int = 0,
  536. @xactid_page14 int = NULL,
  537. @xactid_row14 smallint = NULL,
  538. @xactid_ts14 binary(8) = NULL,
  539.  
  540. @job_id15 int = 0,
  541. @xactid_page15 int = NULL,
  542. @xactid_row15 smallint = NULL,
  543. @xactid_ts15 binary(8) = NULL,
  544.  
  545. @job_id16 int = 0,
  546. @xactid_page16 int = NULL,
  547. @xactid_row16 smallint = NULL,
  548. @xactid_ts16 binary(8) = NULL,
  549.  
  550. @job_id17 int = 0,
  551. @xactid_page17 int = NULL,
  552. @xactid_row17 smallint = NULL,
  553. @xactid_ts17 binary(8) = NULL,
  554.  
  555. @job_id18 int = 0,
  556. @xactid_page18 int = NULL,
  557. @xactid_row18 smallint = NULL,
  558. @xactid_ts18 binary(8) = NULL,
  559.  
  560. @job_id19 int = 0,
  561. @xactid_page19 int = NULL,
  562. @xactid_row19 smallint = NULL,
  563. @xactid_ts19 binary(8) = NULL,
  564.  
  565. @job_id20 int = 0,
  566. @xactid_page20 int = NULL,
  567. @xactid_row20 smallint = NULL,
  568. @xactid_ts20 binary(8) = NULL,
  569.  
  570. @job_id21 int = 0,
  571. @xactid_page21 int = NULL,
  572. @xactid_row21 smallint = NULL,
  573. @xactid_ts21 binary(8) = NULL,
  574.  
  575. @job_id22 int = 0,
  576. @xactid_page22 int = NULL,
  577. @xactid_row22 smallint = NULL,
  578. @xactid_ts22 binary(8) = NULL,
  579.  
  580. @job_id23 int = 0,
  581. @xactid_page23 int = NULL,
  582. @xactid_row23 smallint = NULL,
  583. @xactid_ts23 binary(8) = NULL,
  584.  
  585. @job_id24 int = 0,
  586. @xactid_page24 int = NULL,
  587. @xactid_row24 smallint = NULL,
  588. @xactid_ts24 binary(8) = NULL,
  589.  
  590. @job_id25 int = 0,
  591. @xactid_page25 int = NULL,
  592. @xactid_row25 smallint = NULL,
  593. @xactid_ts25 binary(8) = NULL,
  594.  
  595. @job_id26 int = 0,
  596. @xactid_page26 int = NULL,
  597. @xactid_row26 smallint = NULL,
  598. @xactid_ts26 binary(8) = NULL,
  599.  
  600. @job_id27 int = 0,
  601. @xactid_page27 int = NULL,
  602. @xactid_row27 smallint = NULL,
  603. @xactid_ts27 binary(8) = NULL,
  604.  
  605. @job_id28 int = 0,
  606. @xactid_page28 int = NULL,
  607. @xactid_row28 smallint = NULL,
  608. @xactid_ts28 binary(8) = NULL,
  609.  
  610. @job_id29 int = 0,
  611. @xactid_page29 int = NULL,
  612. @xactid_row29 smallint = NULL,
  613. @xactid_ts29 binary(8) = NULL,
  614.  
  615. @job_id30 int = 0,
  616. @xactid_page30 int = NULL,
  617. @xactid_row30 smallint = NULL,
  618. @xactid_ts30 binary(8) = NULL,
  619.  
  620. @job_id31 int = 0,
  621. @xactid_page31 int = NULL,
  622. @xactid_row31 smallint = NULL,
  623. @xactid_ts31 binary(8) = NULL,
  624.  
  625. @job_id32 int = 0,
  626. @xactid_page32 int = NULL,
  627. @xactid_row32 smallint = NULL,
  628. @xactid_ts32 binary(8) = NULL,
  629.  
  630. @job_id33 int = 0,
  631. @xactid_page33 int = NULL,
  632. @xactid_row33 smallint = NULL,
  633. @xactid_ts33 binary(8) = NULL,
  634.  
  635. @job_id34 int = 0,
  636. @xactid_page34 int = NULL,
  637. @xactid_row34 smallint = NULL,
  638. @xactid_ts34 binary(8) = NULL,
  639.  
  640. @job_id35 int = 0,
  641. @xactid_page35 int = NULL,
  642. @xactid_row35 smallint = NULL,
  643. @xactid_ts35 binary(8) = NULL,
  644.  
  645. @job_id36 int = 0,
  646. @xactid_page36 int = NULL,
  647. @xactid_row36 smallint = NULL,
  648. @xactid_ts36 binary(8) = NULL,
  649.  
  650. @job_id37 int = 0,
  651. @xactid_page37 int = NULL,
  652. @xactid_row37 smallint = NULL,
  653. @xactid_ts37 binary(8) = NULL,
  654.  
  655. @job_id38 int = 0,
  656. @xactid_page38 int = NULL,
  657. @xactid_row38 smallint = NULL,
  658. @xactid_ts38 binary(8) = NULL,
  659.  
  660. @job_id39 int = 0,
  661. @xactid_page39 int = NULL,
  662. @xactid_row39 smallint = NULL,
  663. @xactid_ts39 binary(8) = NULL,
  664.  
  665. @job_id40 int = 0,
  666. @xactid_page40 int = NULL,
  667. @xactid_row40 smallint = NULL,
  668. @xactid_ts40 binary(8) = NULL,
  669.  
  670. @job_id41 int = 0,
  671. @xactid_page41 int = NULL,
  672. @xactid_row41 smallint = NULL,
  673. @xactid_ts41 binary(8) = NULL,
  674.  
  675. @job_id42 int = 0,
  676. @xactid_page42 int = NULL,
  677. @xactid_row42 smallint = NULL,
  678. @xactid_ts42 binary(8) = NULL,
  679.  
  680. @job_id43 int = 0,
  681. @xactid_page43 int = NULL,
  682. @xactid_row43 smallint = NULL,
  683. @xactid_ts43 binary(8) = NULL,
  684.  
  685. @job_id44 int = 0,
  686. @xactid_page44 int = NULL,
  687. @xactid_row44 smallint = NULL,
  688. @xactid_ts44 binary(8) = NULL,
  689.  
  690. @job_id45 int = 0,
  691. @xactid_page45 int = NULL,
  692. @xactid_row45 smallint = NULL,
  693. @xactid_ts45 binary(8) = NULL,
  694.  
  695. @job_id46 int = 0,
  696. @xactid_page46 int = NULL,
  697. @xactid_row46 smallint = NULL,
  698. @xactid_ts46 binary(8) = NULL,
  699.  
  700. @job_id47 int = 0,
  701. @xactid_page47 int = NULL,
  702. @xactid_row47 smallint = NULL,
  703. @xactid_ts47 binary(8) = NULL,
  704.  
  705. @job_id48 int = 0,
  706. @xactid_page48 int = NULL,
  707. @xactid_row48 smallint = NULL,
  708. @xactid_ts48 binary(8) = NULL,
  709.  
  710. @job_id49 int = 0,
  711. @xactid_page49 int = NULL,
  712. @xactid_row49 smallint = NULL,
  713. @xactid_ts49 binary(8) = NULL,
  714.  
  715. @job_id50 int = 0,
  716. @xactid_page50 int = NULL,
  717. @xactid_row50 smallint = NULL,
  718. @xactid_ts50 binary(8) = NULL,
  719.  
  720. @job_id51 int = 0,
  721. @xactid_page51 int = NULL,
  722. @xactid_row51 smallint = NULL,
  723. @xactid_ts51 binary(8) = NULL,
  724.  
  725. @job_id52 int = 0,
  726. @xactid_page52 int = NULL,
  727. @xactid_row52 smallint = NULL,
  728. @xactid_ts52 binary(8) = NULL,
  729.  
  730. @job_id53 int = 0,
  731. @xactid_page53 int = NULL,
  732. @xactid_row53 smallint = NULL,
  733. @xactid_ts53 binary(8) = NULL,
  734.  
  735. @job_id54 int = 0,
  736. @xactid_page54 int = NULL,
  737. @xactid_row54 smallint = NULL,
  738. @xactid_ts54 binary(8) = NULL,
  739.  
  740. @job_id55 int = 0,
  741. @xactid_page55 int = NULL,
  742. @xactid_row55 smallint = NULL,
  743. @xactid_ts55 binary(8) = NULL,
  744.  
  745. @job_id56 int = 0,
  746. @xactid_page56 int = NULL,
  747. @xactid_row56 smallint = NULL,
  748. @xactid_ts56 binary(8) = NULL,
  749.  
  750. @job_id57 int = 0,
  751. @xactid_page57 int = NULL,
  752. @xactid_row57 smallint = NULL,
  753. @xactid_ts57 binary(8) = NULL,
  754.  
  755. @job_id58 int = 0,
  756. @xactid_page58 int = NULL,
  757. @xactid_row58 smallint = NULL,
  758. @xactid_ts58 binary(8) = NULL,
  759.  
  760. @job_id59 int = 0,
  761. @xactid_page59 int = NULL,
  762. @xactid_row59 smallint = NULL,
  763. @xactid_ts59 binary(8) = NULL,
  764.  
  765. @job_id60 int = 0,
  766. @xactid_page60 int = NULL,
  767. @xactid_row60 smallint = NULL,
  768. @xactid_ts60 binary(8) = NULL,
  769.  
  770. @job_id61 int = 0,
  771. @xactid_page61 int = NULL,
  772. @xactid_row61 smallint = NULL,
  773. @xactid_ts61 binary(8) = NULL,
  774.  
  775. @job_id62 int = 0,
  776. @xactid_page62 int = NULL,
  777. @xactid_row62 smallint = NULL,
  778. @xactid_ts62 binary(8) = NULL
  779.  
  780. AS 
  781.  
  782.    set nocount on
  783.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id, @type, 
  784.        @xactid_page, @xactid_row, @xactid_ts,
  785.        getdate())
  786.    if @@error <> 0
  787.       return(1)
  788.    
  789.    if @job_id01 = 0
  790.        return
  791.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id01, @type, 
  792.        @xactid_page01, @xactid_row01, @xactid_ts01,
  793.        getdate())
  794.    if @@error <> 0
  795.       return(1)
  796.    
  797.    if @job_id02 = 0
  798.        return
  799.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id02, @type, 
  800.        @xactid_page02, @xactid_row02, @xactid_ts02,
  801.        getdate())
  802.    if @@error <> 0
  803.       return(1)
  804.    
  805.    if @job_id03 = 0
  806.        return
  807.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id03, @type, 
  808.        @xactid_page03, @xactid_row03, @xactid_ts03,
  809.        getdate())
  810.    if @@error <> 0
  811.       return(1)
  812.    
  813.    if @job_id04 = 0
  814.        return
  815.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id04, @type, 
  816.        @xactid_page04, @xactid_row04, @xactid_ts04,
  817.        getdate())
  818.    if @@error <> 0
  819.       return(1)
  820.    
  821.    if @job_id05 = 0
  822.        return
  823.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id05, @type, 
  824.        @xactid_page05, @xactid_row05, @xactid_ts05,
  825.        getdate())
  826.    if @@error <> 0
  827.       return(1)
  828.    
  829.    if @job_id06 = 0
  830.        return
  831.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id06, @type, 
  832.        @xactid_page06, @xactid_row06, @xactid_ts06,
  833.        getdate())
  834.    if @@error <> 0
  835.       return(1)
  836.    
  837.    if @job_id07 = 0
  838.        return
  839.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id07, @type, 
  840.        @xactid_page07, @xactid_row07, @xactid_ts07,
  841.        getdate())
  842.    if @@error <> 0
  843.       return(1)
  844.    
  845.    if @job_id08 = 0
  846.        return
  847.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id08, @type, 
  848.        @xactid_page08, @xactid_row08, @xactid_ts08,
  849.        getdate())
  850.    if @@error <> 0
  851.       return(1)
  852.    
  853.    if @job_id09 = 0
  854.        return
  855.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id09, @type, 
  856.        @xactid_page09, @xactid_row09, @xactid_ts09,
  857.        getdate())
  858.    if @@error <> 0
  859.       return(1)
  860.    
  861.    if @job_id10 = 0
  862.        return
  863.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id10, @type, 
  864.        @xactid_page10, @xactid_row10, @xactid_ts10,
  865.        getdate())
  866.    if @@error <> 0
  867.       return(1)
  868.    
  869.    if @job_id11 = 0
  870.        return
  871.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id11, @type, 
  872.        @xactid_page11, @xactid_row11, @xactid_ts11,
  873.        getdate())
  874.    if @@error <> 0
  875.       return(1)
  876.    
  877.    if @job_id12 = 0
  878.        return
  879.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id12, @type, 
  880.        @xactid_page12, @xactid_row12, @xactid_ts12,
  881.        getdate())
  882.    if @@error <> 0
  883.       return(1)
  884.    
  885.    if @job_id13 = 0
  886.        return
  887.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id13, @type, 
  888.        @xactid_page13, @xactid_row13, @xactid_ts13,
  889.        getdate())
  890.    if @@error <> 0
  891.       return(1)
  892.    
  893.    if @job_id14 = 0
  894.        return
  895.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id14, @type, 
  896.        @xactid_page14, @xactid_row14, @xactid_ts14,
  897.        getdate())
  898.    if @@error <> 0
  899.       return(1)
  900.    
  901.    if @job_id15 = 0
  902.        return
  903.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id15, @type, 
  904.        @xactid_page15, @xactid_row15, @xactid_ts15,
  905.        getdate())
  906.    if @@error <> 0
  907.       return(1)
  908.    
  909.    if @job_id16 = 0
  910.        return
  911.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id16, @type, 
  912.        @xactid_page16, @xactid_row16, @xactid_ts16,
  913.        getdate())
  914.    if @@error <> 0
  915.       return(1)
  916.    
  917.    if @job_id17 = 0
  918.        return
  919.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id17, @type, 
  920.        @xactid_page17, @xactid_row17, @xactid_ts17,
  921.        getdate())
  922.    if @@error <> 0
  923.       return(1)
  924.    
  925.    if @job_id18 = 0
  926.        return
  927.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id18, @type, 
  928.        @xactid_page18, @xactid_row18, @xactid_ts18,
  929.        getdate())
  930.    if @@error <> 0
  931.       return(1)
  932.    
  933.    if @job_id19 = 0
  934.        return
  935.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id19, @type, 
  936.        @xactid_page19, @xactid_row19, @xactid_ts19,
  937.        getdate())
  938.    if @@error <> 0
  939.       return(1)
  940.    
  941.    if @job_id20 = 0
  942.        return
  943.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id20, @type, 
  944.        @xactid_page20, @xactid_row20, @xactid_ts20,
  945.        getdate())
  946.    if @@error <> 0
  947.       return(1)
  948.    
  949.    if @job_id21 = 0
  950.        return
  951.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id21, @type, 
  952.        @xactid_page21, @xactid_row21, @xactid_ts21,
  953.        getdate())
  954.    if @@error <> 0
  955.       return(1)
  956.    
  957.    if @job_id22 = 0
  958.        return
  959.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id22, @type, 
  960.        @xactid_page22, @xactid_row22, @xactid_ts22,
  961.        getdate())
  962.    if @@error <> 0
  963.       return(1)
  964.    
  965.    if @job_id23 = 0
  966.        return
  967.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id23, @type, 
  968.        @xactid_page23, @xactid_row23, @xactid_ts23,
  969.        getdate())
  970.    if @@error <> 0
  971.       return(1)
  972.    
  973.    if @job_id24 = 0
  974.        return
  975.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id24, @type, 
  976.        @xactid_page24, @xactid_row24, @xactid_ts24,
  977.        getdate())
  978.    if @@error <> 0
  979.       return(1)
  980.    
  981.    if @job_id25 = 0
  982.        return
  983.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id25, @type, 
  984.        @xactid_page25, @xactid_row25, @xactid_ts25,
  985.        getdate())
  986.    if @@error <> 0
  987.       return(1)
  988.    
  989.    if @job_id26 = 0
  990.        return
  991.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id26, @type, 
  992.        @xactid_page26, @xactid_row26, @xactid_ts26,
  993.        getdate())
  994.    if @@error <> 0
  995.       return(1)
  996.    
  997.    if @job_id27 = 0
  998.        return
  999.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id27, @type, 
  1000.        @xactid_page27, @xactid_row27, @xactid_ts27,
  1001.        getdate())
  1002.    if @@error <> 0
  1003.       return(1)
  1004.    
  1005.    if @job_id28 = 0
  1006.        return
  1007.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id28, @type, 
  1008.        @xactid_page28, @xactid_row28, @xactid_ts28,
  1009.        getdate())
  1010.    if @@error <> 0
  1011.       return(1)
  1012.    
  1013.    if @job_id29 = 0
  1014.        return
  1015.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id29, @type, 
  1016.        @xactid_page29, @xactid_row29, @xactid_ts29,
  1017.        getdate())
  1018.    if @@error <> 0
  1019.       return(1)
  1020.    
  1021.    if @job_id30 = 0
  1022.        return
  1023.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id30, @type, 
  1024.        @xactid_page30, @xactid_row30, @xactid_ts30,
  1025.        getdate())
  1026.    if @@error <> 0
  1027.       return(1)
  1028.    
  1029.    if @job_id31 = 0
  1030.        return
  1031.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id31, @type, 
  1032.        @xactid_page31, @xactid_row31, @xactid_ts31,
  1033.        getdate())
  1034.    if @@error <> 0
  1035.       return(1)
  1036.    
  1037.    if @job_id32 = 0
  1038.        return
  1039.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id32, @type, 
  1040.        @xactid_page32, @xactid_row32, @xactid_ts32,
  1041.        getdate())
  1042.    if @@error <> 0
  1043.       return(1)
  1044.    
  1045.    if @job_id33 = 0
  1046.        return
  1047.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id33, @type, 
  1048.        @xactid_page33, @xactid_row33, @xactid_ts33,
  1049.        getdate())
  1050.    if @@error <> 0
  1051.       return(1)
  1052.    
  1053.    if @job_id34 = 0
  1054.        return
  1055.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id34, @type, 
  1056.        @xactid_page34, @xactid_row34, @xactid_ts34,
  1057.        getdate())
  1058.    if @@error <> 0
  1059.       return(1)
  1060.    
  1061.    if @job_id35 = 0
  1062.           return
  1063.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id35, @type, 
  1064.        @xactid_page35, @xactid_row35, @xactid_ts35,
  1065.        getdate())
  1066.    if @@error <> 0
  1067.       return(1)
  1068.    
  1069.    if @job_id36 = 0
  1070.        return
  1071.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id36, @type, 
  1072.        @xactid_page36, @xactid_row36, @xactid_ts36,
  1073.        getdate())
  1074.    if @@error <> 0
  1075.       return(1)
  1076.    
  1077.    if @job_id37 = 0
  1078.        return
  1079.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id37, @type, 
  1080.        @xactid_page37, @xactid_row37, @xactid_ts37,
  1081.        getdate())
  1082.    if @@error <> 0
  1083.       return(1)
  1084.    
  1085.    if @job_id38 = 0
  1086.        return
  1087.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id38, @type, 
  1088.        @xactid_page38, @xactid_row38, @xactid_ts38,
  1089.        getdate())
  1090.    if @@error <> 0
  1091.       return(1)
  1092.    
  1093.    if @job_id39 = 0
  1094.        return
  1095.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id39, @type, 
  1096.        @xactid_page39, @xactid_row39, @xactid_ts39,
  1097.        getdate())
  1098.    if @@error <> 0
  1099.       return(1)
  1100.    
  1101.    if @job_id40 = 0
  1102.        return
  1103.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id40, @type, 
  1104.        @xactid_page40, @xactid_row40, @xactid_ts40,
  1105.        getdate())
  1106.    if @@error <> 0
  1107.       return(1)
  1108.    
  1109.    if @job_id41 = 0
  1110.        return
  1111.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id41, @type, 
  1112.        @xactid_page41, @xactid_row41, @xactid_ts41,
  1113.        getdate())
  1114.    if @@error <> 0
  1115.       return(1)
  1116.    
  1117.    if @job_id42 = 0
  1118.        return
  1119.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id42, @type, 
  1120.        @xactid_page42, @xactid_row42, @xactid_ts42,
  1121.        getdate())
  1122.    if @@error <> 0
  1123.       return(1)
  1124.    
  1125.    if @job_id43 = 0
  1126.        return
  1127.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id43, @type, 
  1128.        @xactid_page43, @xactid_row43, @xactid_ts43,
  1129.        getdate())
  1130.    if @@error <> 0
  1131.       return(1)
  1132.    
  1133.    if @job_id44 = 0
  1134.        return
  1135.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id44, @type, 
  1136.        @xactid_page44, @xactid_row44, @xactid_ts44,
  1137.        getdate())
  1138.    if @@error <> 0
  1139.       return(1)
  1140.    
  1141.    if @job_id45 = 0
  1142.        return
  1143.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id45, @type, 
  1144.        @xactid_page45, @xactid_row45, @xactid_ts45,
  1145.        getdate())
  1146.    if @@error <> 0
  1147.       return(1)
  1148.    
  1149.    if @job_id46 = 0
  1150.        return
  1151.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id46, @type, 
  1152.        @xactid_page46, @xactid_row46, @xactid_ts46,
  1153.        getdate())
  1154.    if @@error <> 0
  1155.       return(1)
  1156.    
  1157.    if @job_id47 = 0
  1158.        return
  1159.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id47, @type, 
  1160.        @xactid_page47, @xactid_row47, @xactid_ts47,
  1161.        getdate())
  1162.    if @@error <> 0
  1163.       return(1)
  1164.    
  1165.    if @job_id48 = 0
  1166.        return
  1167.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id48, @type, 
  1168.        @xactid_page48, @xactid_row48, @xactid_ts48,
  1169.        getdate())
  1170.    if @@error <> 0
  1171.       return(1)
  1172.    
  1173.    if @job_id49 = 0
  1174.        return
  1175.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id49, @type, 
  1176.        @xactid_page49, @xactid_row49, @xactid_ts49,
  1177.        getdate())
  1178.    if @@error <> 0
  1179.       return(1)
  1180.    
  1181.    if @job_id50 = 0
  1182.        return
  1183.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id50, @type, 
  1184.        @xactid_page50, @xactid_row50, @xactid_ts50,
  1185.        getdate())
  1186.    if @@error <> 0
  1187.       return(1)
  1188.    
  1189.    if @job_id51 = 0
  1190.        return
  1191.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id51, @type, 
  1192.        @xactid_page51, @xactid_row51, @xactid_ts51,
  1193.        getdate())
  1194.    if @@error <> 0
  1195.       return(1)
  1196.    
  1197.    if @job_id52 = 0
  1198.        return
  1199.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id52, @type, 
  1200.        @xactid_page52, @xactid_row52, @xactid_ts52,
  1201.        getdate())
  1202.    if @@error <> 0
  1203.       return(1)
  1204.    
  1205.    if @job_id53 = 0
  1206.        return
  1207.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id53, @type, 
  1208.        @xactid_page53, @xactid_row53, @xactid_ts53,
  1209.        getdate())
  1210.    if @@error <> 0
  1211.       return(1)
  1212.    
  1213.    if @job_id54 = 0
  1214.        return
  1215.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id54, @type, 
  1216.        @xactid_page54, @xactid_row54, @xactid_ts54,
  1217.        getdate())
  1218.    if @@error <> 0
  1219.       return(1)
  1220.    
  1221.    if @job_id55 = 0
  1222.        return
  1223.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id55, @type, 
  1224.        @xactid_page55, @xactid_row55, @xactid_ts55,
  1225.        getdate())
  1226.    if @@error <> 0
  1227.       return(1)
  1228.    
  1229.    if @job_id56 = 0
  1230.        return
  1231.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id56, @type, 
  1232.        @xactid_page56, @xactid_row56, @xactid_ts56,
  1233.        getdate())
  1234.    if @@error <> 0
  1235.       return(1)
  1236.    
  1237.    if @job_id57 = 0
  1238.        return
  1239.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id57, @type, 
  1240.        @xactid_page57, @xactid_row57, @xactid_ts57,
  1241.        getdate())
  1242.    if @@error <> 0
  1243.       return(1)
  1244.    
  1245.    if @job_id58 = 0
  1246.        return
  1247.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id58, @type, 
  1248.        @xactid_page58, @xactid_row58, @xactid_ts58,
  1249.        getdate())
  1250.    if @@error <> 0
  1251.       return(1)
  1252.    
  1253.    if @job_id59 = 0
  1254.        return
  1255.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id59, @type, 
  1256.        @xactid_page59, @xactid_row59, @xactid_ts59,
  1257.        getdate())
  1258.    if @@error <> 0
  1259.       return(1)
  1260.    
  1261.    if @job_id60 = 0
  1262.        return
  1263.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id60, @type, 
  1264.        @xactid_page60, @xactid_row60, @xactid_ts60,
  1265.        getdate())
  1266.    if @@error <> 0
  1267.       return(1)
  1268.    
  1269.    if @job_id61 = 0
  1270.        return
  1271.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id61, @type, 
  1272.        @xactid_page61, @xactid_row61, @xactid_ts61,
  1273.        getdate())
  1274.    if @@error <> 0
  1275.       return(1)
  1276.    
  1277.    if @job_id62 = 0
  1278.        return           
  1279.    insert into MSjobs values (@publisher_id, @publisher_db, @job_id62, @type, 
  1280.        @xactid_page62, @xactid_row62, @xactid_ts62,
  1281.        getdate())
  1282.    if @@error <> 0
  1283.       return(1)
  1284.    
  1285.    
  1286. GO
  1287.    
  1288.    /* Set category bit to reflect MS objects */
  1289. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  1290.     name = 'sp_MSadd_job'
  1291. GO
  1292.  
  1293. /****************************************************************************/
  1294. PRINT ''
  1295. PRINT 'Creating Stored Procedure:  dbo.sp_MSadd_job_command'
  1296. PRINT ''
  1297. /****************************************************************************/
  1298. GO
  1299. CREATE PROCEDURE sp_MSadd_job_command
  1300. @publisher_id smallint,
  1301. @publisher_db varchar (30),
  1302. @job_id int,
  1303. @command_id int,
  1304. @art_id int,
  1305. @incomplete bit,
  1306. @command varchar(255),
  1307.  
  1308. @job_id1 int = 0,
  1309. @command_id1 int = 0,
  1310. @art_id1 int = 0,
  1311. @incomplete1 bit = 0,
  1312. @command1 varchar(255) = NULL,
  1313.  
  1314. @job_id2 int = 0,
  1315. @command_id2 int = 0,
  1316. @art_id2 int = 0,
  1317. @incomplete2 bit = 0,
  1318. @command2 varchar(255) = NULL,
  1319.  
  1320. @job_id3 int = 0,
  1321. @command_id3 int = 0,
  1322. @art_id3 int = 0,
  1323. @incomplete3 bit = 0,
  1324. @command3 varchar(255) = NULL,
  1325.  
  1326. @job_id4 int = 0,
  1327. @command_id4 int = 0,
  1328. @art_id4 int = 0,
  1329. @incomplete4 bit = 0,
  1330. @command4 varchar(255) = NULL,
  1331.  
  1332. @job_id5 int = 0,
  1333. @command_id5 int = 0,
  1334. @art_id5 int = 0,
  1335. @incomplete5 bit = 0,
  1336. @command5 varchar(255) = NULL,
  1337.  
  1338. @job_id6 int = 0,
  1339. @command_id6 int = 0,
  1340. @art_id6 int = 0,
  1341. @incomplete6 bit = 0,
  1342. @command6 varchar(255) = NULL,
  1343.  
  1344. @job_id7 int = 0,
  1345. @command_id7 int = 0,
  1346. @art_id7 int = 0,
  1347. @incomplete7 bit = 0,
  1348. @command7 varchar(255) = NULL,
  1349.  
  1350. @job_id8 int = 0,
  1351. @command_id8 int = 0,
  1352. @art_id8 int = 0,
  1353. @incomplete8 bit = 0,
  1354. @command8 varchar(255) = NULL,
  1355.  
  1356. @job_id9 int = 0,
  1357. @command_id9 int = 0,
  1358. @art_id9 int = 0,
  1359. @incomplete9 bit = 0,
  1360. @command9 varchar(255) = NULL,
  1361.  
  1362. @job_id10 int = 0,
  1363. @command_id10 int = 0,
  1364. @art_id10 int = 0,
  1365. @incomplete10 bit = 0,
  1366. @command10 varchar(255) = NULL,
  1367.  
  1368. @job_id11 int = 0,
  1369. @command_id11 int = 0,
  1370. @art_id11 int = 0,
  1371. @incomplete11 bit = 0,
  1372. @command11 varchar(255) = NULL,
  1373.  
  1374. @job_id12 int = 0,
  1375. @command_id12 int = 0,
  1376. @art_id12 int = 0,
  1377. @incomplete12 bit = 0,
  1378. @command12 varchar(255) = NULL,
  1379.  
  1380. @job_id13 int = 0,
  1381. @command_id13 int = 0,
  1382. @art_id13 int = 0,
  1383. @incomplete13 bit = 0,
  1384. @command13 varchar(255) = NULL,
  1385.  
  1386. @job_id14 int = 0,
  1387. @command_id14 int = 0,
  1388. @art_id14 int = 0,
  1389. @incomplete14 bit = 0,
  1390. @command14 varchar(255) = NULL,
  1391.  
  1392. @job_id15 int = 0,
  1393. @command_id15 int = 0,
  1394. @art_id15 int = 0,
  1395. @incomplete15 bit = 0,
  1396. @command15 varchar(255) = NULL,
  1397.  
  1398.  
  1399. @job_id16 int = 0,
  1400. @command_id16 int = 0,
  1401. @art_id16 int = 0,
  1402. @incomplete16 bit = 0,
  1403. @command16 varchar(255) = NULL,
  1404.  
  1405. @job_id17 int = 0,
  1406. @command_id17 int = 0,
  1407. @art_id17 int = 0,
  1408. @incomplete17 bit = 0,
  1409. @command17 varchar(255) = NULL,
  1410.  
  1411. @job_id18 int = 0,
  1412. @command_id18 int = 0,
  1413. @art_id18 int = 0,
  1414. @incomplete18 bit = 0,
  1415. @command18 varchar(255) = NULL,
  1416.  
  1417. @job_id19 int = 0,
  1418. @command_id19 int = 0,
  1419. @art_id19 int = 0,
  1420. @incomplete19 bit = 0,
  1421. @command19 varchar(255) = NULL,
  1422.  
  1423. @job_id20 int = 0,
  1424. @command_id20 int = 0,
  1425. @art_id20 int = 0,
  1426. @incomplete20 bit = 0,
  1427. @command20 varchar(255) = NULL,
  1428.  
  1429. @job_id21 int = 0,
  1430. @command_id21 int = 0,
  1431. @art_id21 int = 0,
  1432. @incomplete21 bit = 0,
  1433. @command21 varchar(255) = NULL,
  1434.  
  1435. @job_id22 int = 0,
  1436. @command_id22 int = 0,
  1437. @art_id22 int = 0,
  1438. @incomplete22 bit = 0,
  1439. @command22 varchar(255) = NULL,
  1440.  
  1441. @job_id23 int = 0,
  1442. @command_id23 int = 0,
  1443. @art_id23 int = 0,
  1444. @incomplete23 bit = 0,
  1445. @command23 varchar(255) = NULL,
  1446.  
  1447. @job_id24 int = 0,
  1448. @command_id24 int = 0,
  1449. @art_id24 int = 0,
  1450. @incomplete24 bit = 0,
  1451. @command24 varchar(255) = NULL,
  1452.  
  1453. @job_id25 int = 0,
  1454. @command_id25 int = 0,
  1455. @art_id25 int = 0,
  1456. @incomplete25 bit = 0,
  1457. @command25 varchar(255) = NULL,
  1458.  
  1459. @job_id26 int = 0,
  1460. @command_id26 int = 0,
  1461. @art_id26 int = 0,
  1462. @incomplete26 bit = 0,
  1463. @command26 varchar(255) = NULL,
  1464.  
  1465. @job_id27 int = 0,
  1466. @command_id27 int = 0,
  1467. @art_id27 int = 0,
  1468. @incomplete27 bit = 0,
  1469. @command27 varchar(255) = NULL,
  1470.  
  1471. @job_id28 int = 0,
  1472. @command_id28 int = 0,
  1473. @art_id28 int = 0,
  1474. @incomplete28 bit = 0,
  1475. @command28 varchar(255) = NULL,
  1476.  
  1477. @job_id29 int = 0,
  1478. @command_id29 int = 0,
  1479. @art_id29 int = 0,
  1480. @incomplete29 bit = 0,
  1481. @command29 varchar(255) = NULL,
  1482.  
  1483. @job_id30 int = 0,
  1484. @command_id30 int = 0,
  1485. @art_id30 int = 0,
  1486. @incomplete30 bit = 0,
  1487. @command30 varchar(255) = NULL,
  1488.  
  1489. @job_id31 int = 0,
  1490. @command_id31 int = 0,
  1491. @art_id31 int = 0,
  1492. @incomplete31 bit = 0,
  1493. @command31 varchar(255) = NULL,
  1494.  
  1495. @job_id32 int = 0,
  1496. @command_id32 int = 0,
  1497. @art_id32 int = 0,
  1498. @incomplete32 bit = 0,
  1499. @command32 varchar(255) = NULL,
  1500.  
  1501. @job_id33 int = 0,
  1502. @command_id33 int = 0,
  1503. @art_id33 int = 0,
  1504. @incomplete33 bit = 0,
  1505. @command33 varchar(255) = NULL,
  1506.  
  1507. @job_id34 int = 0,
  1508. @command_id34 int = 0,
  1509. @art_id34 int = 0,
  1510. @incomplete34 bit = 0,
  1511. @command34 varchar(255) = NULL,
  1512.  
  1513. @job_id35 int = 0,
  1514. @command_id35 int = 0,
  1515. @art_id35 int = 0,
  1516. @incomplete35 bit = 0,
  1517. @command35 varchar(255) = NULL,
  1518.  
  1519.  
  1520. @job_id36 int = 0,
  1521. @command_id36 int = 0,
  1522. @art_id36 int = 0,
  1523. @incomplete36 bit = 0,
  1524. @command36 varchar(255) = NULL,
  1525.  
  1526. @job_id37 int = 0,
  1527. @command_id37 int = 0,
  1528. @art_id37 int = 0,
  1529. @incomplete37 bit = 0,
  1530. @command37 varchar(255) = NULL,
  1531.  
  1532. @job_id38 int = 0,
  1533. @command_id38 int = 0,
  1534. @art_id38 int = 0,
  1535. @incomplete38 bit = 0,
  1536. @command38 varchar(255) = NULL,
  1537.  
  1538. @job_id39 int = 0,
  1539. @command_id39 int = 0,
  1540. @art_id39 int = 0,
  1541. @incomplete39 bit = 0,
  1542. @command39 varchar(255) = NULL,
  1543.  
  1544. @job_id40 int = 0,
  1545. @command_id40 int = 0,
  1546. @art_id40 int = 0,
  1547. @incomplete40 bit = 0,
  1548. @command40 varchar(255) = NULL,
  1549.  
  1550. @job_id41 int = 0,
  1551. @command_id41 int = 0,
  1552. @art_id41 int = 0,
  1553. @incomplete41 bit = 0,
  1554. @command41 varchar(255) = NULL,
  1555.  
  1556. @job_id42 int = 0,
  1557. @command_id42 int = 0,
  1558. @art_id42 int = 0,
  1559. @incomplete42 bit = 0,
  1560. @command42 varchar(255) = NULL,
  1561.  
  1562. @job_id43 int = 0,
  1563. @command_id43 int = 0,
  1564. @art_id43 int = 0,
  1565. @incomplete43 bit = 0,
  1566. @command43 varchar(255) = NULL,
  1567.  
  1568. @job_id44 int = 0,
  1569. @command_id44 int = 0,
  1570. @art_id44 int = 0,
  1571. @incomplete44 bit = 0,
  1572. @command44 varchar(255) = NULL,
  1573.  
  1574. @job_id45 int = 0,
  1575. @command_id45 int = 0,
  1576. @art_id45 int = 0,
  1577. @incomplete45 bit = 0,
  1578. @command45 varchar(255) = NULL,
  1579.  
  1580. @job_id46 int = 0,
  1581. @command_id46 int = 0,
  1582. @art_id46 int = 0,
  1583. @incomplete46 bit = 0,
  1584. @command46 varchar(255) = NULL,
  1585.  
  1586. @job_id47 int = 0,
  1587. @command_id47 int = 0,
  1588. @art_id47 int = 0,
  1589. @incomplete47 bit = 0,
  1590. @command47 varchar(255) = NULL,
  1591.  
  1592. @job_id48 int = 0,
  1593. @command_id48 int = 0,
  1594. @art_id48 int = 0,
  1595. @incomplete48 bit = 0,
  1596. @command48 varchar(255) = NULL,
  1597.  
  1598. @job_id49 int = 0,
  1599. @command_id49 int = 0,
  1600. @art_id49 int = 0,
  1601. @incomplete49 bit = 0,
  1602. @command49 varchar(255) = NULL
  1603.  
  1604. as
  1605.  
  1606.    set nocount on
  1607.    
  1608.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id,
  1609.        @command_id, @art_id, @incomplete, @command)
  1610.    if @@error <> 0
  1611.       return(1)
  1612.    
  1613.    if (@job_id1 <> 0)
  1614.    begin
  1615.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id1 ,
  1616.        @command_id1 , @art_id1, @incomplete1, @command1)
  1617.    if @@error <> 0
  1618.       return(1)
  1619.    end
  1620.    else
  1621.    return 0
  1622.    
  1623.    if (@job_id2 <> 0)
  1624.    begin
  1625.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id2 ,
  1626.        @command_id2 , @art_id2, @incomplete2, @command2)
  1627.    if @@error <> 0
  1628.       return(1)
  1629.    end
  1630.    else
  1631.    return 0
  1632.    
  1633.    if (@job_id3 <> 0)
  1634.    begin
  1635.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id3 ,
  1636.        @command_id3 , @art_id3, @incomplete3, @command3)
  1637.    if @@error <> 0
  1638.       return(1)
  1639.    end
  1640.    else
  1641.    return 0
  1642.    
  1643.    if (@job_id4 <> 0)
  1644.    begin
  1645.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id4 ,
  1646.        @command_id4 , @art_id4, @incomplete4, @command4)
  1647.    if @@error <> 0
  1648.       return(1)
  1649.    end
  1650.    else
  1651.    return 0
  1652.    
  1653.    if (@job_id5 <> 0)
  1654.    begin
  1655.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id5 ,
  1656.        @command_id5 , @art_id5, @incomplete5, @command5)
  1657.    if @@error <> 0
  1658.       return(1)
  1659.    end
  1660.    else
  1661.    return 0
  1662.    
  1663.    if (@job_id6 <> 0)
  1664.    begin
  1665.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id6 ,
  1666.        @command_id6 , @art_id6, @incomplete6, @command6)
  1667.    if @@error <> 0
  1668.       return(1)
  1669.    end
  1670.    else
  1671.    return 0
  1672.    
  1673.    if (@job_id7 <> 0)
  1674.    begin
  1675.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id7 ,
  1676.        @command_id7 , @art_id7, @incomplete7, @command7)
  1677.    if @@error <> 0
  1678.       return(1)
  1679.    end
  1680.    else
  1681.    return 0
  1682.    
  1683.    if (@job_id8 <> 0)
  1684.    begin
  1685.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id8 ,
  1686.        @command_id8 , @art_id8, @incomplete8, @command8)
  1687.    if @@error <> 0
  1688.       return(1)
  1689.    end
  1690.    else
  1691.    return 0
  1692.    
  1693.    if (@job_id9 <> 0)
  1694.    begin
  1695.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id9 ,
  1696.        @command_id9 , @art_id9, @incomplete9, @command9)
  1697.    if @@error <> 0
  1698.       return(1)
  1699.    end
  1700.    else
  1701.    return 0
  1702.    
  1703.    if (@job_id10 <> 0)
  1704.    begin
  1705.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id10,
  1706.        @command_id10,  @art_id10, @incomplete10, @command10)
  1707.    if @@error <> 0
  1708.       return(1)
  1709.    end
  1710.    else
  1711.    return 0
  1712.    
  1713.    if (@job_id11 <> 0)
  1714.    begin
  1715.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id11,
  1716.        @command_id11,  @art_id11, @incomplete11, @command11)
  1717.    if @@error <> 0
  1718.       return(1)
  1719.    end
  1720.    else
  1721.    return 0
  1722.    
  1723.    if (@job_id12 <> 0)
  1724.    begin
  1725.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id12,
  1726.        @command_id12,  @art_id12, @incomplete12, @command12)
  1727.    if @@error <> 0
  1728.       return(1)
  1729.    end
  1730.    else
  1731.    return 0
  1732.    
  1733.    if (@job_id13 <> 0)
  1734.    begin
  1735.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id13,
  1736.        @command_id13,  @art_id13, @incomplete13, @command13)
  1737.    if @@error <> 0
  1738.       return(1)
  1739.    end
  1740.    else
  1741.    return 0
  1742.    
  1743.    if (@job_id14 <> 0)
  1744.    begin
  1745.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id14,
  1746.        @command_id14,  @art_id14, @incomplete14, @command14)
  1747.    if @@error <> 0
  1748.       return(1)
  1749.    end
  1750.    else
  1751.    return 0
  1752.    
  1753.    if (@job_id15 <> 0)
  1754.    begin
  1755.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id15,
  1756.        @command_id15,  @art_id15, @incomplete15, @command15)
  1757.    if @@error <> 0
  1758.       return(1)
  1759.    end
  1760.    else
  1761.    return 0
  1762.    
  1763.    if (@job_id16 <> 0)
  1764.    begin
  1765.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id16,
  1766.        @command_id16,  @art_id16, @incomplete16, @command16)
  1767.    if @@error <> 0
  1768.       return(1)
  1769.    end
  1770.    else
  1771.    return 0
  1772.    
  1773.    if (@job_id17 <> 0)
  1774.    begin
  1775.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id17,
  1776.        @command_id17,  @art_id17, @incomplete17, @command17)
  1777.    if @@error <> 0
  1778.       return(1)
  1779.    end
  1780.    else
  1781.    return 0
  1782.  
  1783.    
  1784.    if (@job_id18 <> 0)
  1785.    begin
  1786.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id18,
  1787.        @command_id18,  @art_id18, @incomplete18, @command18)
  1788.    if @@error <> 0
  1789.       return(1)
  1790.    end
  1791.    else
  1792.    return 0
  1793.    
  1794.    if (@job_id19 <> 0)
  1795.    begin
  1796.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id19,
  1797.        @command_id19, @art_id19, @incomplete19, @command19)
  1798.    if @@error <> 0
  1799.       return(1)
  1800.    end
  1801.    else
  1802.    return 0
  1803.    
  1804.    if (@job_id20 <> 0)
  1805.    begin
  1806.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id20,
  1807.        @command_id20, @art_id20, @incomplete20, @command20)
  1808.    if @@error <> 0
  1809.       return(1)
  1810.    end
  1811.    else
  1812.    return 0
  1813.    
  1814.    if (@job_id21 <> 0)
  1815.    begin
  1816.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id21,
  1817.        @command_id21, @art_id21, @incomplete21, @command21)
  1818.    if @@error <> 0
  1819.       return(1)
  1820.    end
  1821.    else
  1822.    return 0
  1823.    
  1824.    if (@job_id22 <> 0)
  1825.    begin
  1826.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id22,
  1827.        @command_id22, @art_id22, @incomplete22, @command22)
  1828.    if @@error <> 0
  1829.       return(1)
  1830.    end
  1831.    else
  1832.    return 0
  1833.    
  1834.    if (@job_id23 <> 0)
  1835.    begin
  1836.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id23,
  1837.        @command_id23, @art_id23, @incomplete23, @command23)
  1838.    if @@error <> 0
  1839.       return(1)
  1840.    end
  1841.    else
  1842.    return 0
  1843.    
  1844.    if (@job_id24 <> 0)
  1845.    begin
  1846.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id24,
  1847.        @command_id24, @art_id24, @incomplete24, @command24)
  1848.    if @@error <> 0
  1849.       return(1)
  1850.    end
  1851.    else
  1852.    return 0
  1853.    
  1854.    if (@job_id25 <> 0)
  1855.    begin
  1856.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id25,
  1857.        @command_id25, @art_id25, @incomplete25, @command25)
  1858.    if @@error <> 0
  1859.       return(1)
  1860.    end
  1861.    else
  1862.    return 0
  1863.    
  1864.    if (@job_id26 <> 0)
  1865.    begin
  1866.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id26,
  1867.        @command_id26, @art_id26, @incomplete26, @command26)
  1868.    if @@error <> 0
  1869.       return(1)
  1870.    end
  1871.    else
  1872.    return 0
  1873.    
  1874.    if (@job_id27 <> 0)
  1875.    begin
  1876.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id27,
  1877.        @command_id27, @art_id27, @incomplete27, @command27)
  1878.    if @@error <> 0
  1879.       return(1)
  1880.    end
  1881.    else
  1882.    return 0
  1883.    
  1884.    if (@job_id28 <> 0)
  1885.    begin
  1886.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id28,
  1887.        @command_id28, @art_id28, @incomplete28, @command28)
  1888.    if @@error <> 0
  1889.       return(1)
  1890.    end
  1891.    else
  1892.    return 0
  1893.    
  1894.    if (@job_id29 <> 0)
  1895.    begin
  1896.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id29,
  1897.        @command_id29, @art_id29, @incomplete29, @command29)
  1898.    if @@error <> 0
  1899.       return(1)
  1900.    end
  1901.    else
  1902.    return 0
  1903.    
  1904.    if (@job_id30 <> 0)
  1905.    begin
  1906.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id30,
  1907.        @command_id30, @art_id30, @incomplete30, @command30)
  1908.    if @@error <> 0
  1909.       return(1)
  1910.    end
  1911.    else
  1912.    return 0
  1913.    
  1914.    if (@job_id31 <> 0)
  1915.    begin
  1916.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id31,
  1917.        @command_id31, @art_id31, @incomplete31, @command31)
  1918.    if @@error <> 0
  1919.       return(1)
  1920.    end
  1921.    else
  1922.    return 0
  1923.    
  1924.    if (@job_id32 <> 0)
  1925.    begin
  1926.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id32,
  1927.        @command_id32, @art_id32, @incomplete32, @command32)
  1928.    if @@error <> 0
  1929.       return(1)
  1930.    end
  1931.    else
  1932.    return 0
  1933.    
  1934.    if (@job_id33 <> 0)
  1935.    begin
  1936.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id33,
  1937.        @command_id33, @art_id33, @incomplete33, @command33)
  1938.    if @@error <> 0
  1939.       return(1)
  1940.    end
  1941.    else
  1942.    return 0
  1943.    
  1944.    if (@job_id34 <> 0)
  1945.    begin
  1946.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id34,
  1947.        @command_id34, @art_id34, @incomplete34, @command34)
  1948.    if @@error <> 0
  1949.       return(1)
  1950.    end
  1951.    else
  1952.    return 0
  1953.    
  1954.    if (@job_id35 <> 0)
  1955.    begin
  1956.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id35,
  1957.        @command_id35, @art_id35, @incomplete35, @command35)
  1958.    if @@error <> 0
  1959.       return(1)
  1960.    end
  1961.    else
  1962.    return 0
  1963.    
  1964.    if (@job_id36 <> 0)
  1965.    begin
  1966.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id36,
  1967.        @command_id36, @art_id36, @incomplete36, @command36)
  1968.    if @@error <> 0
  1969.       return(1)
  1970.    end
  1971.    else
  1972.    return 0
  1973.    
  1974.    if (@job_id37 <> 0)
  1975.    begin
  1976.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id37,
  1977.        @command_id37, @art_id37, @incomplete37,  @command37)
  1978.    if @@error <> 0
  1979.       return(1)
  1980.    end
  1981.    else
  1982.    return 0
  1983.    
  1984.    if (@job_id38 <> 0)
  1985.    begin
  1986.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id38,
  1987.        @command_id38, @art_id38, @incomplete38, @command38)
  1988.    if @@error <> 0
  1989.       return(1)
  1990.    end
  1991.    else
  1992.    return 0
  1993.    
  1994.    if (@job_id39 <> 0)
  1995.    begin
  1996.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id39,
  1997.        @command_id39, @art_id39, @incomplete39, @command39)
  1998.    if @@error <> 0
  1999.       return(1)
  2000.    end
  2001.    else
  2002.    return 0
  2003.    
  2004.    if (@job_id40 <> 0)
  2005.    begin
  2006.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id40,
  2007.        @command_id40, @art_id40, @incomplete40, @command40)
  2008.    if @@error <> 0
  2009.       return(1)
  2010.    end
  2011.    else
  2012.    return 0
  2013.    
  2014.    if (@job_id41 <> 0)
  2015.    begin
  2016.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id41,
  2017.        @command_id41, @art_id41, @incomplete41, @command41)
  2018.    if @@error <> 0
  2019.       return(1)
  2020.    end
  2021.    else
  2022.    return 0
  2023.    
  2024.    if (@job_id42 <> 0)
  2025.    begin
  2026.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id42,
  2027.        @command_id42, @art_id42, @incomplete42, @command42)
  2028.    if @@error <> 0
  2029.       return(1)
  2030.    end
  2031.    else
  2032.    return 0
  2033.    
  2034.    if (@job_id43 <> 0)
  2035.    begin
  2036.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id43,
  2037.        @command_id43, @art_id43, @incomplete43, @command43)
  2038.    if @@error <> 0
  2039.       return(1)
  2040.    end
  2041.    else
  2042.    return 0
  2043.    
  2044.    if (@job_id44 <> 0)
  2045.    begin
  2046.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id44,
  2047.        @command_id44, @art_id44, @incomplete44, @command44)
  2048.    if @@error <> 0
  2049.       return(1)
  2050.    end
  2051.    else
  2052.    return 0
  2053.    
  2054.    if (@job_id45 <> 0)
  2055.    begin
  2056.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id45,
  2057.        @command_id45, @art_id45, @incomplete45, @command45)
  2058.    if @@error <> 0
  2059.       return(1)
  2060.    end
  2061.    else
  2062.    return 0
  2063.    
  2064.    if (@job_id46 <> 0)
  2065.    begin
  2066.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id46,
  2067.        @command_id46, @art_id46, @incomplete46, @command46)
  2068.    if @@error <> 0
  2069.       return(1)
  2070.    end
  2071.    else
  2072.    return 0
  2073.    
  2074.    if (@job_id47 <> 0)
  2075.    begin
  2076.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id47,
  2077.        @command_id47, @art_id47, @incomplete47, @command47)
  2078.    if @@error <> 0
  2079.       return(1)
  2080.    end
  2081.    else
  2082.    return 0
  2083.    
  2084.    if (@job_id48 <> 0)
  2085.    begin
  2086.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id48,
  2087.        @command_id48, @art_id48, @incomplete48, @command48)
  2088.    if @@error <> 0
  2089.       return(1)
  2090.    end
  2091.    else
  2092.    return 0
  2093.    
  2094.    if (@job_id49 <> 0)
  2095.    begin
  2096.    insert into MSjob_commands values (@publisher_id, @publisher_db, @job_id49,
  2097.        @command_id49, @art_id49, @incomplete49, @command49)
  2098.    if @@error <> 0
  2099.       return(1)
  2100.    end
  2101.    else
  2102.    return 0
  2103.    
  2104. GO
  2105.  
  2106. /* Set category bit to reflect MS objects */
  2107. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2108.     name = 'sp_MSadd_job_command'
  2109. go
  2110.  
  2111. /****************************************************************************/
  2112. PRINT ''
  2113. PRINT 'Creating Stored Procedure:  dbo.sp_MSsubscriber_status'
  2114. PRINT ''
  2115. /****************************************************************************/
  2116. GO
  2117. CREATE PROCEDURE sp_MSsubscriber_status
  2118. @publisher_id smallint,
  2119. @publisher_db varchar (30),
  2120. @job_id int,
  2121. @subscriber_id smallint,
  2122. @subscriber_db varchar (30),
  2123. @delivered_jobs int = 0,
  2124. @delivery_time int = 0,        /* milliseconds */
  2125. @status int
  2126.  
  2127. AS
  2128.  
  2129.    set nocount on 
  2130.    
  2131.    declare @entry_time datetime
  2132.    declare @completion_time datetime
  2133.    declare @total_delivered_jobs int
  2134.    declare @delivery_latency int
  2135.    declare @delivery_rate int
  2136.    declare @delivery_seconds real
  2137.    
  2138.    /*
  2139.    ** If the status record already exists, return.
  2140.    */
  2141.    if exists (select * from MSsubscriber_status where job_id = @job_id and
  2142.       publisher_id = @publisher_id and
  2143.       publisher_db = @publisher_db and
  2144.       subscriber_id = @subscriber_id and
  2145.       subscriber_db = @subscriber_db)
  2146.        return (0)
  2147.    
  2148.    begin transaction sp_MSsubscriber_status
  2149.    
  2150.    /* Get the entry time of the job_id of this status record */
  2151.    select @entry_time = entry_time from MSjobs where
  2152.       publisher_id = @publisher_id and
  2153.       publisher_db = @publisher_db and
  2154.       job_id = @job_id
  2155.    
  2156.    /* Calculate delivery lantency of the job */
  2157.    select @completion_time = getdate()
  2158.    select @delivery_latency = datediff(second, @entry_time, @completion_time)
  2159.    if @delivery_latency is null
  2160.       select @delivery_latency = 0
  2161.    
  2162.    if @delivery_time is null
  2163.       select @delivery_time = 0
  2164.    
  2165.    /* Calculate transactions delivered/sec */
  2166.    if @delivery_time <> 0
  2167.       begin
  2168.          select @delivery_seconds = @delivery_time/1000.0
  2169.          select @delivery_rate = @delivered_jobs / @delivery_seconds
  2170.       end
  2171.    
  2172.    if @delivery_rate is null
  2173.       select @delivery_rate = 0
  2174.    
  2175.    insert MSsubscriber_status values (@publisher_id, @publisher_db, @job_id,
  2176.       @subscriber_id, @subscriber_db, @completion_time, @delivery_latency,
  2177.       @delivered_jobs, @delivery_rate, @status)
  2178.    if @@error <> 0
  2179.       begin
  2180.          rollback transaction sp_MSsubscriber_status
  2181.          return (1)
  2182.       end
  2183.    
  2184.    commit transaction sp_MSsubscriber_status
  2185. GO
  2186.  
  2187. /* Set category bit to reflect MS objects */
  2188. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2189.     name = 'sp_MSsubscriber_status'
  2190. GO
  2191.  
  2192. /****************************************************************************/
  2193. PRINT ''
  2194. PRINT 'Creating Stored Procedure:  dbo.sp_MSadd_subscription'
  2195. PRINT ''
  2196. /****************************************************************************/
  2197. GO
  2198. CREATE PROCEDURE sp_MSadd_subscription
  2199. @publisher varchar (30),
  2200. @publisher_db varchar (30),
  2201. @subscriber varchar (30),
  2202. @art_id int,
  2203. @subscriber_db varchar (30),
  2204. @status tinyint,    /* 0 = inactive, 1 = subscribed, 2 = active */
  2205. @sub_ts binary (8)
  2206.  
  2207. as
  2208.  
  2209. set nocount on
  2210.  
  2211.    declare @publisher_id smallint
  2212.    declare @subscriber_id smallint
  2213.    declare @command varchar (255)
  2214.    declare @type tinyint
  2215.    declare @commit_batch_size int
  2216.    declare @status_batch_size int
  2217.    declare @frequency_type int
  2218.    declare @frequency_interval int
  2219.    declare @frequency_relative_interval int
  2220.    declare @frequency_recurrence_factor int
  2221.    declare @frequency_subday int
  2222.    declare @frequency_subday_interval int
  2223.    declare @active_start_time_of_day int
  2224.    declare @active_end_time_of_day int
  2225.    declare @active_start_date int
  2226.    declare @active_end_date int
  2227.    declare @database varchar (30)
  2228.    declare @name varchar (60)
  2229.    declare @retcode int
  2230.    declare @login varchar (30)
  2231.    declare @password varchar (30)
  2232.    declare @retryattempts int
  2233.    declare @retrydelay int
  2234.    
  2235.    
  2236.    begin transaction MSadd_subscription
  2237.    
  2238.    select @publisher_id = srvid from master..sysservers where
  2239.        srvname = @publisher
  2240.    select @subscriber_id = srvid from master..sysservers where
  2241.        srvname = @subscriber
  2242.    
  2243.    /*
  2244.    ** Insert subscription
  2245.    */
  2246.    insert into MSjob_subscriptions values (@publisher, @publisher_id,
  2247.        @publisher_db, @subscriber, @subscriber_id, @art_id,
  2248.        @subscriber_db, @status, @sub_ts)
  2249.    if @@ERROR <> 0
  2250.        begin
  2251.            rollback transaction MSadd_subscription
  2252.        return (1)
  2253.        end
  2254.    
  2255.    /*
  2256.    ** If no subscriber information then return
  2257.    */
  2258.    if not exists (select * from MSsubscriber_info where
  2259.        publisher = @publisher and
  2260.     subscriber = @subscriber)
  2261.     begin
  2262.        commit transaction MSadd_subscription
  2263.        return 0
  2264.     end
  2265.  
  2266.    /* Construct task command */
  2267.    select @command = '-S' + @subscriber  + ' '
  2268.    select @login = login, @password = password,
  2269.        @type = type, @commit_batch_size = commit_batch_size,
  2270.        @status_batch_size = status_batch_size
  2271.        from
  2272.        MSsubscriber_info
  2273.        where
  2274.        publisher = @publisher and
  2275.        subscriber = @subscriber
  2276.    if @login is not null
  2277.        select @command = @command  + '-U' + @login + ' '
  2278.    if @password is not null
  2279.        select @command = @command  + '-P' + @password+ ' '
  2280.    select @command = @command  + '-d' + @subscriber_db + ' '
  2281.    select @command = @command + '-p' + @publisher + ' '
  2282.    if @type = 1 /* Commit is always 1 for non-SQL Server subscribers */
  2283.       select @commit_batch_size = 1
  2284.    if @commit_batch_size is not null and @commit_batch_size <> 0
  2285.        select @command = @command + '-c' + convert (varchar(10),@commit_batch_size) + ' '
  2286.    if @status_batch_size is not null and @status_batch_size <> 0
  2287.        select @command = @command + '-b' + convert (varchar(10),@status_batch_size) + ' '
  2288.    select @command = @command + '-n' + @publisher_db + ' '
  2289.    select @command = @command + '-i2000 '
  2290.    select @command = @command + '-t' + convert (varchar(10),@type) + ' '
  2291.    
  2292.    /*
  2293.    ** Construct unique name
  2294.    */
  2295.    select @name =  @publisher + '_' + @publisher_db + '_' +
  2296.        @subscriber + '_' + @subscriber_db
  2297.    
  2298.    /*
  2299.    ** Create a distribution task, if one does not already exists.
  2300.    */
  2301.    if exists (select * from msdb..systasks_view where
  2302.        subsystem = 'Distribution' and
  2303.        name = @name)
  2304.        begin
  2305.            commit transaction MSadd_subscription
  2306.        return 0
  2307.        end
  2308.    
  2309.    /*
  2310.    ** Get sp_addtask parameters from MSsubscriber_info
  2311.    */
  2312.    select @database = DB_name()
  2313.    select @frequency_type = frequency_type,
  2314.           @frequency_interval = frequency_interval,
  2315.           @frequency_relative_interval = frequency_relative_interval,
  2316.           @frequency_recurrence_factor = frequency_recurrence_factor,
  2317.           @frequency_subday = frequency_subday,
  2318.           @frequency_subday_interval = frequency_subday_interval,
  2319.           @active_start_time_of_day = active_start_time_of_day,
  2320.           @active_end_time_of_day = active_end_time_of_day,
  2321.           @active_start_date = active_start_date,
  2322.           @active_end_date = active_end_date,
  2323.           @retryattempts = retryattempts,
  2324.           @retrydelay = retrydelay
  2325.           from MSsubscriber_info where
  2326.           publisher = @publisher and
  2327.           subscriber = @subscriber
  2328.    
  2329.    execute @retcode = msdb..sp_addtask
  2330.        @name = @name,
  2331.        @subsystem = 'Distribution',
  2332.        @server = @@SERVERNAME,
  2333.        @username = NULL,
  2334.        @databasename = @database,
  2335.        @enabled = 1,
  2336.        @freqtype = @frequency_type,
  2337.        @freqinterval = @frequency_interval,
  2338.        @freqsubtype = @frequency_subday,
  2339.        @freqsubinterval = @frequency_subday_interval,
  2340.        @freqrelativeinterval = @frequency_relative_interval,
  2341.        @freqrecurrencefactor = 0,
  2342.        @activestartdate = @active_start_date,
  2343.        @activeenddate = @active_end_date,
  2344.        @activestarttimeofday = @active_start_time_of_day,
  2345.        @activeendtimeofday = @active_end_time_of_day,
  2346.        @nextrundate = 0,
  2347.        @nextruntime = 0,
  2348.        @runpriority = 0,
  2349.        @emailoperatorname = NULL,
  2350.        @retryattempts = @retryattempts,
  2351.        @retrydelay = @retrydelay,
  2352.        @command = @command,
  2353.        @loghistcompletionlevel = 0,
  2354.        @emailcompletionlevel = 0,
  2355.        @description = NULL
  2356.    if @@ERROR <> 0 or @retcode <> 0
  2357.       begin
  2358.           rollback transaction MSadd_subscription
  2359.           return (1)
  2360.       end
  2361.    
  2362.    /* Make sure the task is owned by 'repl_subscriber' */
  2363.    if (suser_id() = 1)
  2364.       begin
  2365.          exec @retcode =  msdb.dbo.sp_reassigntask @name, 'repl_subscriber', 'sa'
  2366.          if @@ERROR <> 0 or @retcode <> 0
  2367.             begin
  2368.                rollback transaction MSadd_subscription
  2369.            return (1)
  2370.         end
  2371.       end
  2372.    
  2373.    commit transaction MSadd_subscription
  2374. GO
  2375.  
  2376. /* Set category bit to reflect MS objects */
  2377. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2378.     name = 'sp_MSadd_subscription'
  2379. GO
  2380.  
  2381. /****************************************************************************/
  2382. PRINT ''
  2383. PRINT 'Creating Stored Procedure:  dbo.sp_MSdrop_subscription'
  2384. PRINT ''
  2385. /****************************************************************************/
  2386. GO
  2387. CREATE PROCEDURE sp_MSdrop_subscription
  2388. @publisher varchar (30),
  2389. @publisher_db varchar (30),
  2390. @subscriber varchar (30),
  2391. @art_id int,
  2392. @subscriber_db varchar (30)
  2393.  
  2394. as
  2395.  
  2396.    set nocount on
  2397.    
  2398.    declare @publisher_id smallint
  2399.    declare @subscriber_id smallint
  2400.    declare @name varchar (60)
  2401.    declare @retcode int
  2402.    
  2403.    begin transaction MSdrop_subscription
  2404.    
  2405.    select @publisher_id = srvid from master..sysservers where
  2406.        srvname = @publisher
  2407.    select @subscriber_id = srvid from master..sysservers where
  2408.        srvname = @subscriber
  2409.    
  2410.    /* Delete the all subscriber jobs based on the subscription */
  2411.    delete from MSsubscriber_jobs where
  2412.        publisher_id = @publisher_id and
  2413.        publisher_db = @publisher_db and
  2414.        subscriber_id = @subscriber_id and
  2415.        subscriber_db = @subscriber_db and
  2416.        job_id in (select distinct job_id
  2417.            from MSjob_commands (index = ucMSjob_commands)
  2418.            where
  2419.            publisher_id = @publisher_id and
  2420.            publisher_db = @publisher_db and
  2421.            art_id = @art_id)
  2422.    
  2423.    if @@ERROR <> 0
  2424.        begin
  2425.            rollback transaction MSdrop_subscription
  2426.        return 1
  2427.        end
  2428.    
  2429.    /* Delete the subscription */
  2430.    delete from MSjob_subscriptions where
  2431.        art_id = @art_id and
  2432.        publisher_id = @publisher_id and
  2433.        publisher_db = @publisher_db and
  2434.        subscriber_id = @subscriber_id and
  2435.        subscriber_db = @subscriber_db
  2436.    
  2437.    if @@ERROR <> 0
  2438.        begin
  2439.            rollback transaction MSdrop_subscription
  2440.        return 1
  2441.        end
  2442.    
  2443.    /*
  2444.    ** If there are other subscriptions on the subscriber database,
  2445.    ** then return.  Otherwise, delete corresponding distribution process and
  2446.    ** set last job xactid_page = -1.
  2447.    */
  2448.    if exists (select * from MSjob_subscriptions where
  2449.        subscriber = @subscriber and
  2450.        subscriber_db = @subscriber_db)
  2451.        begin
  2452.           commit transaction MSdrop_subscription
  2453.           return 0
  2454.        end
  2455.    
  2456.    /* Set transaction rid value to -1, 0. This signals the Log Reader to
  2457.    ** go to last distributed transaction.
  2458.    */     
  2459.    update MSjobs set xactid_page = -1, xactid_row = 0 where
  2460.        publisher_id = @publisher_id and
  2461.        publisher_db = @publisher_db  and
  2462.        job_id = (select max(job_id) from MSjobs where
  2463.           publisher_id = @publisher_id and
  2464.           publisher_db = @publisher_db)
  2465.    if @@error <> 0
  2466.          return (1)
  2467.  
  2468.    /*
  2469.    ** Drop the distribution task, if one exists.
  2470.    */
  2471.    select @name =  @publisher + '_' + @publisher_db + '_' +
  2472.        @subscriber + '_' + @subscriber_db
  2473.    if not exists (select * from msdb..systasks_view where
  2474.       name = @name)
  2475.        begin
  2476.            commit transaction MSdrop_subscription
  2477.        return 0
  2478.        end
  2479.    
  2480.    /*
  2481.    ** Delete distribution task.
  2482.    */
  2483.    execute @retcode = msdb..sp_droptask @name = @name
  2484.    if @@ERROR <> 0 or @retcode <> 0
  2485.        begin
  2486.            rollback transaction MSdrop_subscription
  2487.        return 1
  2488.        end
  2489.    
  2490.    commit transaction MSdrop_subscription
  2491. GO
  2492.  
  2493. /* Set category bit to reflect MS objects */
  2494. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2495.     name = 'sp_MSdrop_subscription'
  2496. GO
  2497.  
  2498. /****************************************************************************/
  2499. PRINT ''
  2500. PRINT 'Creating Stored Procedure:  dbo.sp_MSupdate_subscription'
  2501. PRINT ''
  2502. /****************************************************************************/
  2503. GO
  2504. CREATE PROCEDURE sp_MSupdate_subscription
  2505. @publisher varchar (30),
  2506. @publisher_db varchar (30),
  2507. @subscriber varchar (30),
  2508. @art_id int,
  2509. @status int,
  2510. @sub_ts binary (8)
  2511.  
  2512. as
  2513.  
  2514.    set nocount on
  2515.    
  2516.    declare @publisher_id smallint
  2517.    declare @subscriber_id smallint
  2518.    
  2519.    begin transaction MSupdate_subscription
  2520.    
  2521.    select @publisher_id = srvid from master..sysservers where
  2522.        srvname = @publisher
  2523.    select @subscriber_id = srvid from master..sysservers where
  2524.        srvname = @subscriber
  2525.    
  2526.    /*
  2527.    ** If the subscription is not defined then return.
  2528.    */
  2529.    if not exists (select * from MSjob_subscriptions where
  2530.        publisher_id = @publisher_id and
  2531.        publisher_db = @publisher_db and
  2532.        subscriber_id = @subscriber_id and
  2533.        art_id = @art_id)
  2534.        begin
  2535.            rollback transaction MSupdate_subscription
  2536.            return (1)
  2537.        end
  2538.    
  2539.    /*
  2540.    ** Update subscription
  2541.    */
  2542.    update MSjob_subscriptions set status = @status, ts = @sub_ts where
  2543.       publisher_id = @publisher_id and
  2544.       publisher_db = @publisher_db and
  2545.       subscriber_id = @subscriber_id and
  2546.       art_id = @art_id 
  2547.    if @@ERROR <> 0
  2548.       begin
  2549.       rollback transaction MSupdate_subscription
  2550.       return (1)
  2551.       end
  2552.    
  2553.    commit transaction MSupdate_subscription
  2554. GO
  2555.  
  2556. /* Set category bit to reflect MS objects */
  2557. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2558.     name = 'sp_MSupdate_subscription'
  2559. GO
  2560.  
  2561. /****************************************************************************/
  2562. PRINT ''
  2563. PRINT 'Creating Stored Procedure:  dbo.sp_MSadd_subscriber_job'
  2564. PRINT ''
  2565. /****************************************************************************/
  2566. GO
  2567. CREATE PROCEDURE sp_MSadd_subscriber_job
  2568. @publisher_id smallint = 0,
  2569. @publisher_db varchar ( 30), 
  2570. @job_id int,
  2571. @subscriber varchar (30) = '%'
  2572. AS
  2573.    set nocount on
  2574.    set forceplan on
  2575.    
  2576.    /*
  2577.    ** To receive sql commands the subscription status must be 'active'.
  2578.    */
  2579.    if ((select type from MSjobs (index = ucMSjobs) where
  2580.       publisher_id = @publisher_id and publisher_db = @publisher_db and
  2581.       job_id = @job_id) = 0)
  2582.       begin
  2583.          insert MSsubscriber_jobs select @publisher_id, @publisher_db,
  2584.         jc.job_id, s.subscriber_id, s.subscriber_db, jc.command_id from
  2585.             MSjob_commands jc (index = ucMSjob_commands),
  2586.         MSjobs j (index = ucMSjobs),
  2587.             MSjob_subscriptions s (index = ucMSsubscriptions)
  2588.             where
  2589.         jc.publisher_id = @publisher_id and
  2590.         jc.publisher_db = @publisher_db and
  2591.             jc.job_id >= @job_id and 
  2592.         j.publisher_id = jc.publisher_id and
  2593.         j.publisher_db = jc.publisher_db and
  2594.             j.job_id = jc.job_id and 
  2595.             s.publisher_id = jc.publisher_id and
  2596.             s.publisher_db = jc.publisher_db and
  2597.             s.art_id = jc.art_id and
  2598.             s.subscriber like @subscriber and
  2599.         s.status = 2 and
  2600.             s.ts <= j.xactid_ts 
  2601.       end
  2602.    else
  2603.       begin
  2604.          insert MSsubscriber_jobs select @publisher_id, @publisher_db,
  2605.         jc.job_id, s.subscriber_id, s.subscriber_db, jc.command_id from
  2606.             MSjob_commands jc (index = ucMSjob_commands),
  2607.         MSjobs j (index = ucMSjobs),
  2608.             MSjob_subscriptions s (index = ucMSsubscriptions)
  2609.             where
  2610.         jc.publisher_id = @publisher_id and
  2611.         jc.publisher_db = @publisher_db and
  2612.             jc.job_id >= @job_id and 
  2613.         j.publisher_id = jc.publisher_id and
  2614.         j.publisher_db = jc.publisher_db and
  2615.             j.job_id = jc.job_id and 
  2616.             s.publisher_id = jc.publisher_id and
  2617.             s.publisher_db = jc.publisher_db and
  2618.             s.art_id = jc.art_id and
  2619.             s.subscriber like @subscriber and
  2620.         s.status > 0 and
  2621.             s.ts <= j.xactid_ts 
  2622.       end
  2623.    
  2624.    if @@error <> 0
  2625.       return(1)
  2626.    
  2627. GO
  2628.  
  2629. /* Set category bit to reflect MS objects */
  2630. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2631.     name = 'sp_MSadd_subscriber_job'
  2632. GO
  2633.  
  2634. /****************************************************************************/
  2635. PRINT ''
  2636. PRINT 'Creating Stored Procedure:  dbo.sp_MSget_subscriber_jobs'
  2637. PRINT ''
  2638. /****************************************************************************/
  2639. GO
  2640. CREATE PROCEDURE sp_MSget_subscriber_jobs
  2641. @publisher_id smallint,
  2642. @publisher_db varchar (30) = '%',
  2643. @subscriber_id smallint,
  2644. @subscriber_db varchar (30),
  2645. @last_job_id int,
  2646. @num_jobs int = 0
  2647.  
  2648. as
  2649.  
  2650.    set nocount on
  2651.    set forceplan on
  2652.    
  2653.    select jc.job_id, jc.incomplete, j.type, jc.command
  2654.       from
  2655.       MSsubscriber_jobs sj (index = ucMSsubscriber_jobs),
  2656.       MSjob_commands jc (NOLOCK), 
  2657.       MSjobs j (NOLOCK)
  2658.       where
  2659.       sj.publisher_id = @publisher_id and
  2660.       sj.publisher_db = @publisher_db and
  2661.       sj.job_id >= (select min(sj.job_id)
  2662.        from
  2663.        MSsubscriber_jobs sj (index = ucMSsubscriber_jobs)
  2664.        where
  2665.        sj.publisher_id = @publisher_id and
  2666.        sj.publisher_db = @publisher_db and
  2667.        sj.job_id > @last_job_id and
  2668.        sj.subscriber_id = @subscriber_id and
  2669.        sj.subscriber_db = @subscriber_db ) and
  2670.       (@num_jobs = 0 or
  2671.       sj.job_id < @num_jobs + (select min(sj.job_id)
  2672.        from
  2673.        MSsubscriber_jobs sj (index = ucMSsubscriber_jobs)
  2674.        where
  2675.        sj.publisher_id = @publisher_id and
  2676.        sj.publisher_db = @publisher_db and
  2677.        sj.job_id > @last_job_id and
  2678.        sj.subscriber_id = @subscriber_id and
  2679.        sj.subscriber_db = @subscriber_db)) and
  2680.        sj.subscriber_id = @subscriber_id and
  2681.        sj.subscriber_db = @subscriber_db and
  2682.        jc.publisher_id = sj.publisher_id and
  2683.        jc.publisher_db = sj.publisher_db and
  2684.        jc.job_id = sj.job_id and
  2685.        jc.command_id = sj.command_id and
  2686.        j.job_id = sj.job_id and
  2687.        j.publisher_id = sj.publisher_id and
  2688.        j.publisher_db = sj.publisher_db
  2689. GO
  2690.  
  2691. /* Set category bit to reflect MS objects */
  2692. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2693.     name = 'sp_MSget_subscriber_jobs'
  2694. GO
  2695.  
  2696. /****************************************************************************/
  2697. PRINT ''
  2698. PRINT 'Creating Stored Procedure:  dbo.sp_MSfind_subscriber_job'
  2699. PRINT ''
  2700. /****************************************************************************/
  2701. GO
  2702. CREATE PROCEDURE sp_MSfind_subscriber_job
  2703. @publisher_id smallint,
  2704. @publisher_db varchar (30),
  2705. @subscriber_id smallint,
  2706. @subscriber_db varchar (30),
  2707. @job_id int
  2708.  
  2709. as
  2710.  
  2711.    set nocount on
  2712.    
  2713.    select job_id
  2714.       from
  2715.       MSsubscriber_jobs (index = ucMSsubscriber_jobs)
  2716.       where
  2717.       publisher_db = @publisher_db and
  2718.       publisher_id = @publisher_id and
  2719.       subscriber_db = @subscriber_db and
  2720.       subscriber_id = @subscriber_id and
  2721.       job_id = @job_id 
  2722. GO
  2723.  
  2724. /* Set category bit to reflect MS objects */
  2725. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2726.     name = 'sp_MSfind_subscriber_job'
  2727. GO
  2728.  
  2729. /****************************************************************************/
  2730. PRINT ''
  2731. PRINT 'Creating Stored Procedure:  dbo.sp_MSget_last_job'
  2732. PRINT ''
  2733. /****************************************************************************/
  2734. GO
  2735. CREATE PROCEDURE sp_MSget_last_job
  2736. @publisher_id int,
  2737. @publisher_db varchar (30),
  2738. @ex_tablock bit = 0
  2739.  
  2740. AS
  2741.  
  2742.    set nocount on 
  2743.    
  2744.    if @ex_tablock = 1
  2745.       select max(job_id) from MSjobs (TABLOCKX index = ucMSjobs) where
  2746.        publisher_id = @publisher_id
  2747.        and publisher_db = @publisher_db
  2748.    else
  2749.       select max(job_id) from MSjobs (UPDLOCK index = ucMSjobs) where
  2750.        publisher_id = @publisher_id
  2751.        and publisher_db = @publisher_db
  2752.  
  2753. GO
  2754.  
  2755. /* Set category bit to reflect MS objects */
  2756. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2757.     name = 'sp_MSget_last_job'
  2758. GO
  2759.  
  2760. /****************************************************************************/
  2761. PRINT ''
  2762. PRINT 'Creating Stored Procedure:  dbo.sp_MSget_last_trans'
  2763. PRINT ''
  2764. /****************************************************************************/
  2765. GO
  2766. CREATE PROCEDURE sp_MSget_last_trans
  2767. @publisher_id int,
  2768. @publisher_db varchar (30)
  2769.  
  2770. AS
  2771.  
  2772.    set nocount on 
  2773.    
  2774.    select job_id, xactid_page, xactid_row, xactid_ts, type from MSjobs where 
  2775.        publisher_id = @publisher_id and
  2776.        publisher_db = @publisher_db and
  2777.        job_id = (select max(job_id) from MSjobs
  2778.            where publisher_id = @publisher_id
  2779.            and publisher_db = @publisher_db
  2780.            and not (xactid_page = 0 and xactid_row = 0))
  2781.    
  2782. GO
  2783.    
  2784. /* Set category bit to reflect MS objects */
  2785. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2786.     name = 'sp_MSget_last_trans'
  2787. GO
  2788.  
  2789. /****************************************************************************/
  2790. PRINT ''
  2791. PRINT 'Creating Stored Procedure:  dbo.sp_MSadd_subscriber_info'
  2792. PRINT ''
  2793. /****************************************************************************/
  2794. GO
  2795. CREATE PROCEDURE sp_MSadd_subscriber_info
  2796. @publisher varchar (30),
  2797. @subscriber varchar (30),
  2798. @type tinyint,
  2799. @login varchar (30) = NULL,
  2800. @password varchar (30) = NULL,
  2801. @commit_batch_size int,
  2802. @status_batch_size int,
  2803. @flush_frequency int,
  2804. @frequency_type int,
  2805. @frequency_interval int,
  2806. @frequency_relative_interval int,
  2807. @frequency_recurrence_factor int,
  2808. @frequency_subday int,
  2809. @frequency_subday_interval int,
  2810. @active_start_time_of_day int,
  2811. @active_end_time_of_day int,
  2812. @active_start_date int,
  2813. @active_end_date int,
  2814. @retryattempts int = 0,    
  2815. @retrydelay int = 0,
  2816. @description varchar (255) = NULL
  2817.  
  2818. AS
  2819.    set nocount on
  2820.    
  2821.    declare @name varchar (30)
  2822.    declare @database varchar (30)
  2823.    declare @command varchar (255)
  2824.    declare @retcode int
  2825.    
  2826.    /* Add the subscriber to sysservers as a RPC server, if it does not
  2827.    ** already exist.
  2828.    */
  2829.    if not exists (select * from  master..sysservers where  srvname = @subscriber)
  2830.       begin
  2831.           exec @retcode = sp_addserver @subscriber
  2832.           if @retcode <> 0
  2833.              return 1
  2834.       end
  2835.    
  2836.    /*
  2837.    ** Set default retries for continuous distribution task to every minute
  2838.    ** for 24 hours.
  2839.    **
  2840.    */
  2841.    if @retryattempts = 0 and @retrydelay = 0 and @frequency_type = 64
  2842.       begin
  2843.        select @retryattempts = 1440
  2844.        select @retrydelay = 1
  2845.       end
  2846.  
  2847.    /* Delete any existing row */
  2848.    if exists (select * from MSsubscriber_info where
  2849.        publisher = @publisher and
  2850.        subscriber = @subscriber)
  2851.        begin
  2852.            delete from MSsubscriber_info where publisher = @publisher and
  2853.          subscriber = @subscriber
  2854.           if @@error <> 0
  2855.              return 1
  2856.        end
  2857.  
  2858.    insert MSsubscriber_info (publisher, subscriber, type, login, password,
  2859.       commit_batch_size, status_batch_size, flush_frequency,
  2860.       frequency_type, frequency_interval, frequency_relative_interval,
  2861.       frequency_recurrence_factor, frequency_subday, frequency_subday_interval,
  2862.       active_start_time_of_day, active_end_time_of_day, active_start_date,
  2863.       active_end_date, retryattempts, retrydelay, description)
  2864.       values (@publisher, @subscriber, @type, @login, @password,
  2865.       @commit_batch_size, @status_batch_size, @flush_frequency,
  2866.       @frequency_type, @frequency_interval, @frequency_relative_interval,
  2867.       @frequency_recurrence_factor, @frequency_subday, @frequency_subday_interval,
  2868.       @active_start_time_of_day, @active_end_time_of_day, @active_start_date,
  2869.       @active_end_date, @retryattempts, @retrydelay, @description)
  2870.    if @@error <> 0
  2871.       return 1
  2872.    
  2873.    /*
  2874.    ** Create a distribution cleanup task for the subscriber, if one does not
  2875.    ** already exists.
  2876.    */
  2877.    select @name =  @publisher + '_' + @subscriber + '_Cleanup'
  2878.    
  2879.    if exists (select * from msdb..systasks_view where
  2880.        subsystem = 'TSQL' and
  2881.        name = @name)
  2882.        begin
  2883.        return 0
  2884.        end
  2885.    
  2886.    select @database = DB_name()
  2887.    
  2888.    /* Construct task command */
  2889.    select @command = @database + '..' + 'sp_replcleanup ' + '' + @publisher +
  2890.        '' + ', ' + '' + @subscriber  +  '' + ', ' +
  2891.        CONVERT( varchar(10), @flush_frequency)
  2892.    
  2893.    execute @retcode = msdb..sp_addtask
  2894.        @name = @name,
  2895.        @subsystem = 'TSQL',
  2896.        @server = @@SERVERNAME,
  2897.        @username = NULL,
  2898.        @databasename = @database, 
  2899.        @enabled = 1,
  2900.        @freqtype = 4,
  2901.        @freqinterval = 1,
  2902.        @freqsubtype = 1,
  2903.        @freqsubinterval = 0,
  2904.        @freqrelativeinterval = 1,
  2905.        @freqrecurrencefactor = 1,
  2906.        @activestartdate = @active_start_date,
  2907.        @activeenddate = @active_end_date,
  2908.        @activestarttimeofday = 10500,
  2909.        @activeendtimeofday = 235959,
  2910.        @nextrundate = 0,
  2911.        @nextruntime = 0,
  2912.        @runpriority = 0,
  2913.        @emailoperatorname = NULL,
  2914.        @retryattempts = 0,
  2915.        @retrydelay = 0,
  2916.        @command = @command,
  2917.        @loghistcompletionlevel = 0,
  2918.        @emailcompletionlevel = 0,
  2919.        @description = NULL
  2920.    if @@ERROR <> 0 or @retcode <> 0
  2921.       begin
  2922.           return (1)
  2923.       end
  2924. GO
  2925.  
  2926. /* Set category bit to reflect MS objects */
  2927. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  2928.     name = 'sp_MSadd_subscriber_info'
  2929. GO
  2930.  
  2931. /****************************************************************************/
  2932. PRINT ''
  2933. PRINT 'Creating Stored Procedure:  dbo.sp_MSupdate_subscriber_info'
  2934. PRINT ''
  2935. /****************************************************************************/
  2936. GO
  2937. CREATE PROCEDURE sp_MSupdate_subscriber_info
  2938. @publisher varchar (30),
  2939. @subscriber varchar (30),
  2940. @type tinyint = NULL,
  2941. @login varchar (30) = NULL,
  2942. @password varchar (30) = NULL,
  2943. @commit_batch_size int = NULL,
  2944. @status_batch_size int = NULL,
  2945. @flush_frequency int = NULL,
  2946. @frequency_type int = NULL,
  2947. @frequency_interval int = NULL,
  2948. @frequency_relative_interval int = NULL,
  2949. @frequency_recurrence_factor int = NULL,
  2950. @frequency_subday int = NULL,
  2951. @frequency_subday_interval int = NULL,
  2952. @active_start_time_of_day int = NULL,
  2953. @active_end_time_of_day int = NULL,
  2954. @active_start_date int = NULL,
  2955. @active_end_date int = NULL,
  2956. @retryattempts int = NULL,
  2957. @retrydelay int = NULL,
  2958. @description varchar (255) = NULL
  2959.  
  2960. AS
  2961.    set nocount on
  2962.    
  2963.    declare @cmd1 varchar (255)
  2964.    declare @task_id int
  2965.    declare @retcode int
  2966.    
  2967.    begin transaction update_subscriber
  2968.    
  2969.    /* Check if subscriber exists */
  2970.    if not exists (select * from MSsubscriber_info where publisher = @publisher and subscriber = @subscriber)
  2971.        goto FAILED
  2972.    
  2973.    if @type is not NULL
  2974.       update MSsubscriber_info set type = @type where publisher = @publisher and subscriber = @subscriber
  2975.       if @@error <> 0
  2976.          goto FAILED
  2977.    
  2978.    if @login is not NULL
  2979.       update MSsubscriber_info set login = @login where publisher = @publisher and subscriber = @subscriber
  2980.       if @@error <> 0
  2981.          goto FAILED
  2982.    
  2983.    if @password is not NULL
  2984.       update MSsubscriber_info set password = @password where publisher = @publisher and subscriber = @subscriber
  2985.       if @@error <> 0
  2986.          goto FAILED
  2987.    
  2988.    if @commit_batch_size is not NULL
  2989.       update MSsubscriber_info set commit_batch_size = @commit_batch_size where publisher = @publisher and subscriber = @subscriber
  2990.       if @@error <> 0
  2991.          goto FAILED
  2992.    
  2993.    if @status_batch_size is not NULL
  2994.       update MSsubscriber_info set status_batch_size = @status_batch_size where publisher = @publisher and subscriber = @subscriber
  2995.       if @@error <> 0
  2996.          goto FAILED
  2997.    
  2998.    if @flush_frequency is not NULL
  2999.       update MSsubscriber_info set flush_frequency = @flush_frequency where publisher = @publisher and subscriber = @subscriber
  3000.       if @@error <> 0
  3001.          goto FAILED
  3002.    
  3003.    if @frequency_type is not NULL
  3004.       update MSsubscriber_info set frequency_type = @frequency_type where publisher = @publisher and subscriber = @subscriber
  3005.       if @@error <> 0
  3006.          goto FAILED
  3007.    
  3008.    if @frequency_interval is not NULL
  3009.       update MSsubscriber_info set frequency_interval = @frequency_interval where publisher = @publisher and subscriber = @subscriber
  3010.       if @@error <> 0
  3011.          goto FAILED
  3012.    
  3013.    if @frequency_relative_interval is not NULL
  3014.       update MSsubscriber_info set frequency_relative_interval = @frequency_relative_interval where publisher = @publisher and subscriber = @subscriber
  3015.       if @@error <> 0
  3016.          goto FAILED
  3017.    
  3018.    if @frequency_recurrence_factor is not NULL
  3019.       update MSsubscriber_info set frequency_recurrence_factor = @frequency_recurrence_factor where publisher = @publisher and subscriber = @subscriber
  3020.       if @@error <> 0
  3021.          goto FAILED
  3022.    
  3023.    if @frequency_subday is not NULL
  3024.       update MSsubscriber_info set frequency_subday = @frequency_subday where publisher = @publisher and subscriber = @subscriber
  3025.       if @@error <> 0
  3026.          goto FAILED
  3027.    
  3028.    if @frequency_subday_interval is not NULL
  3029.       update MSsubscriber_info set frequency_subday_interval = @frequency_subday_interval where publisher = @publisher and subscriber = @subscriber
  3030.       if @@error <> 0
  3031.          goto FAILED
  3032.    
  3033.    if @active_start_time_of_day is not NULL
  3034.       update MSsubscriber_info set active_start_time_of_day = @active_start_time_of_day where publisher = @publisher and subscriber = @subscriber
  3035.       if @@error <> 0
  3036.          goto FAILED
  3037.    
  3038.    if @active_end_time_of_day is not NULL
  3039.       update MSsubscriber_info set active_end_time_of_day = @active_end_time_of_day where publisher = @publisher and subscriber = @subscriber
  3040.       if @@error <> 0
  3041.          goto FAILED
  3042.    
  3043.    if @active_start_date is not NULL
  3044.       update MSsubscriber_info set active_start_date = @active_start_date where publisher = @publisher and subscriber = @subscriber
  3045.       if @@error <> 0
  3046.          goto FAILED
  3047.    
  3048.    if @active_end_date is not NULL
  3049.       update MSsubscriber_info set active_end_date = @active_end_date where publisher = @publisher and subscriber = @subscriber
  3050.       if @@error <> 0
  3051.          goto FAILED
  3052.    
  3053.    if @retryattempts is not NULL
  3054.       update MSsubscriber_info set retryattempts = @retryattempts where publisher = @publisher and subscriber = @subscriber
  3055.       if @@error <> 0
  3056.          goto FAILED
  3057.    
  3058.    if @retrydelay is not NULL
  3059.       update MSsubscriber_info set retrydelay = @retrydelay where publisher = @publisher and subscriber = @subscriber
  3060.       if @@error <> 0
  3061.          goto FAILED
  3062.    
  3063.    if @description is not NULL
  3064.       update MSsubscriber_info set description = @description where publisher = @publisher and subscriber = @subscriber
  3065.       if @@error <> 0
  3066.          goto FAILED
  3067.  
  3068.     /* Update all distribution task for the subscriber */
  3069.    select @cmd1 = 'declare hC1 scroll cursor for '
  3070.    select @cmd1 = @cmd1 + 'select id from msdb.dbo.systasks_view where '
  3071.    select @cmd1 = @cmd1 + 'subsystem = ''Distribution'' and server = '
  3072.    select @cmd1 = @cmd1 + '''' + @subscriber + ''''
  3073.    EXECUTE (@cmd1)
  3074.    OPEN hC1
  3075.    FETCH hC1 INTO @task_id
  3076.    WHILE (@@fetch_status <> -1)
  3077.       BEGIN
  3078.        exec @retcode = msdb..sp_updatetask
  3079.           @id = @task_id,
  3080.           @freqtype = @frequency_type,
  3081.           @freqinterval = @frequency_interval,
  3082.           @freqsubtype = @frequency_subday,
  3083.           @freqsubinterval = @frequency_subday_interval,
  3084.           @freqrelativeinterval = @frequency_relative_interval,
  3085.           @freqrecurrencefactor = @frequency_recurrence_factor,
  3086.           @activestartdate = @active_start_date,
  3087.           @activeenddate = @active_end_date,
  3088.           @activestarttimeofday = @active_start_time_of_day,
  3089.           @activeendtimeofday = @active_end_time_of_day,
  3090.           @retryattempts =  @retryattempts,
  3091.           @retrydelay = @retrydelay
  3092.        if @@error <> 0 OR @retcode <> 0
  3093.           begin
  3094.              CLOSE hC1
  3095.              DEALLOCATE hC1
  3096.              goto FAILED
  3097.           end
  3098.        FETCH hC1 INTO @task_id
  3099.       END
  3100.    CLOSE hC1
  3101.    DEALLOCATE hC1
  3102.    
  3103.    commit transaction update_subscriber
  3104.    return (0)
  3105.    
  3106. FAILED:
  3107.    
  3108.    rollback transaction update_subscriber
  3109.    return (1)
  3110. GO
  3111.  
  3112. /* Set category bit to reflect MS objects */
  3113. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3114.     name = 'sp_MSupdate_subscriber_info'
  3115. GO
  3116.  
  3117. /****************************************************************************/
  3118. PRINT ''
  3119. PRINT 'Creating Stored Procedure:  dbo.sp_MSdrop_subscriber_info'
  3120. PRINT ''
  3121. /****************************************************************************/
  3122. GO
  3123. CREATE PROCEDURE sp_MSdrop_subscriber_info
  3124. @publisher varchar (30),
  3125. @subscriber varchar (30)
  3126.  
  3127. AS
  3128.    set nocount on
  3129.    
  3130.    declare @name varchar (30)
  3131.    declare @retcode int
  3132.    
  3133.    if exists (select * from MSsubscriber_info where
  3134.        subscriber = @subscriber)
  3135.        begin
  3136.            delete MSsubscriber_info where publisher = @publisher and subscriber = @subscriber
  3137.            if @@error <> 0
  3138.                return 1
  3139.        end
  3140.    /*
  3141.    ** Drop the distribution cleanup task for the subscriber, if one exists.
  3142.    */
  3143.    select @name =  @publisher + '_' + @subscriber + '_Cleanup'
  3144.    
  3145.    if not exists (select * from msdb..systasks_view where
  3146.        subsystem = 'TSQL' and name = @name)
  3147.        begin
  3148.        return 0
  3149.        end
  3150.    
  3151.    execute @retcode = msdb..sp_droptask @name = @name
  3152.    if @@ERROR <> 0 or @retcode <> 0
  3153.        begin
  3154.        return 1
  3155.        end
  3156.    
  3157. GO
  3158.  
  3159. /* Set category bit to reflect MS objects */
  3160. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3161.     name = 'sp_MSdrop_subscriber_info'
  3162. GO
  3163.  
  3164. /****************************************************************************/
  3165. PRINT ''
  3166. PRINT 'Creating Stored Procedure:  dbo.sp_MShelp_subscriber_info'
  3167. PRINT ''
  3168. /****************************************************************************/
  3169. GO
  3170. CREATE PROCEDURE sp_MShelp_subscriber_info
  3171. @publisher varchar (30),
  3172. @subscriber varchar (30)
  3173.  
  3174. AS
  3175.    set nocount on
  3176.    
  3177.    select * from MSsubscriber_info where publisher = @publisher and subscriber = @subscriber
  3178. GO
  3179.  
  3180. /* Set category bit to reflect MS objects */
  3181. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3182.     name = 'sp_MShelp_subscriber_info'
  3183. GO
  3184.  
  3185. /****************************************************************************/
  3186. PRINT ''
  3187. PRINT 'Creating Stored Procedure:  dbo.sp_MSkill_job'
  3188. PRINT ''
  3189. /****************************************************************************/
  3190. GO
  3191. CREATE PROCEDURE sp_MSkill_job
  3192.  
  3193. @job_id int,
  3194. @publisher varchar (30),
  3195. @publisher_db varchar (30),
  3196. @subscriber varchar (30) = '%',
  3197. @subscriber_db varchar (30) = '%'
  3198.  
  3199. as
  3200.  
  3201.    set nocount on
  3202.    
  3203.    delete from MSsubscriber_jobs where job_id = @job_id and
  3204.        publisher_id = (select srvid from master..sysservers where
  3205.            srvname = @publisher) and
  3206.        publisher_db = @publisher_db and
  3207.        subscriber_id IN (select srvid from master..sysservers where
  3208.            srvname like @subscriber) and
  3209.        subscriber_db like @subscriber_db
  3210.    if @@error <> 0
  3211.       return 1
  3212.    
  3213. GO
  3214.  
  3215. /* Set category bit to reflect MS objects */
  3216. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3217.     name = 'sp_MSkill_job'
  3218. GO
  3219.  
  3220. dump transaction distribution with no_log
  3221. go
  3222.  
  3223. /****************************************************************************/
  3224. PRINT ''
  3225. PRINT 'Creating Stored Procedure:  dbo.sp_MSnew_sync'
  3226. PRINT ''
  3227. /****************************************************************************/
  3228. GO
  3229. CREATE PROCEDURE sp_MSnew_sync
  3230. @publisher_id smallint,
  3231. @publisher_db varchar (30),
  3232. @last_job_id int,
  3233. @article_id int,
  3234. @subscriber varchar (30)
  3235.  
  3236. as
  3237.  
  3238.    set nocount on
  3239.    
  3240.    declare @subscriber_id int
  3241.    
  3242.    /* Get the subscriber's id */
  3243.    select @subscriber_id = srvid from master..sysservers where
  3244.        srvname = @subscriber
  3245.    
  3246.    /*
  3247.    ** Remove all previous subscriber jobs for each subscriber in the new
  3248.    ** sync job.
  3249.    */
  3250.    delete from MSsubscriber_jobs where
  3251.        publisher_id = @publisher_id AND
  3252.        publisher_db = @publisher_db AND
  3253.        subscriber_id = @subscriber_id and
  3254.        job_id in
  3255.             (select distinct job_id from MSjob_commands
  3256.             (index = ucMSjob_commands) where
  3257.             publisher_id = @publisher_id AND
  3258.             publisher_db = @publisher_db AND
  3259.             job_id <= @last_job_id AND
  3260.             art_id = @article_id)
  3261.    if @@error <> 0
  3262.          return (1)
  3263.  
  3264. GO
  3265.  
  3266. /* Set category bit to reflect MS objects */
  3267. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3268.     name = 'sp_MSnew_sync'
  3269. GO
  3270.  
  3271. print ''
  3272. print 'Creating procedure sp_MSdistribution_counters'
  3273. go
  3274. CREATE PROCEDURE sp_MSdistribution_counters (
  3275.         @publisher varchar(30)      /* publication server name */
  3276.         ) AS
  3277.  
  3278.     SET NOCOUNT ON
  3279.     SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  3280.  
  3281.     DECLARE @publisher_id smallint
  3282.     DECLARE @subscriber_id smallint
  3283.     DECLARE @publisher_db varchar(30)
  3284.     DECLARE @subscriber varchar(30)
  3285.     DECLARE @subscriber_db varchar(30)
  3286.     DECLARE @max_ss_jobid int
  3287.     DECLARE @delivered_jobs int
  3288.     DECLARE @undelivered_jobs int
  3289.     DECLARE @delivery_rate int
  3290.     DECLARE @delivery_latency int
  3291.  
  3292.     /* Make sure publisher is defined on distributor */
  3293.     SELECT @publisher_id = srvid FROM master..sysservers WHERE
  3294.     srvname = @publisher
  3295.     if @publisher_id is null
  3296.        return (1)
  3297.  
  3298.    create table #distcounters (
  3299.     publisher_db varchar (30),
  3300.         subscriber varchar (30),
  3301.     subscriber_id smallint,
  3302.     subscriber_db varchar (30),
  3303.     delivered_jobs int,
  3304.     undelivered_jobs int,
  3305.     delivery_rate int,
  3306.     delivery_latency int)
  3307.  
  3308.     /* Open a cursor to get each publisher/subscriber database pair */
  3309.     declare hC cursor for select distinct publisher_db,
  3310.       subscriber, subscriber_id, subscriber_db
  3311.       from MSjob_subscriptions
  3312.       where publisher_id = @publisher_id for read only
  3313.       
  3314.     open hC
  3315.     fetch hC into @publisher_db, @subscriber, @subscriber_id,
  3316.        @subscriber_db
  3317.     while (@@fetch_status <> -1)
  3318.       begin
  3319.      select @max_ss_jobid = NULL
  3320.      select @delivery_rate = NULL
  3321.      select @delivery_latency = NULL
  3322.  
  3323.          /*
  3324.      ** Get the subscriber status info of the last subscriber status
  3325.      ** entry.
  3326.      */
  3327.      select @max_ss_jobid = job_id,
  3328.         @delivery_rate = delivery_rate,
  3329.         @delivery_latency = delivery_latency from
  3330.         MSsubscriber_status (index = ucMSsubscriber_status) where
  3331.         publisher_id = @publisher_id and
  3332.         publisher_db = @publisher_db and
  3333.         subscriber_id = @subscriber_id and
  3334.         subscriber_db = @subscriber_db and
  3335.         job_id = (select max(job_id) from MSsubscriber_status ss2
  3336.            (index = ucMSsubscriber_status) where
  3337.            publisher_id = @publisher_id and
  3338.            publisher_db = @publisher_db and
  3339.            subscriber_id = @subscriber_id and
  3340.            subscriber_db = @subscriber_db)
  3341.  
  3342.      /* Get the number of delivered jobs */
  3343.      select @delivered_jobs = count (distinct job_id) from
  3344.         MSsubscriber_jobs (index = ucMSsubscriber_jobs) where
  3345.         publisher_id = @publisher_id and
  3346.         publisher_db = @publisher_db and
  3347.         subscriber_id = @subscriber_id and
  3348.         subscriber_db = @subscriber_db and
  3349.         job_id <= isnull(@max_ss_jobid, 0)
  3350.  
  3351.      /* Get the number of undelivered jobs */
  3352.      select @undelivered_jobs = count (distinct job_id) from
  3353.         MSsubscriber_jobs (index = ucMSsubscriber_jobs) where
  3354.         publisher_id = @publisher_id and
  3355.         publisher_db = @publisher_db and
  3356.         subscriber_id = @subscriber_id and
  3357.         subscriber_db = @subscriber_db and
  3358.         job_id > isnull(@max_ss_jobid, 0)
  3359.  
  3360.       insert into #distcounters values (
  3361.         @publisher_db,
  3362.         @subscriber,
  3363.         @subscriber_id,
  3364.         @subscriber_db,
  3365.         isnull(@delivered_jobs, 0),
  3366.         isnull(@undelivered_jobs, 0),
  3367.         isnull(@delivery_rate, 0),
  3368.         isnull(@delivery_latency, 0))
  3369.  
  3370.      fetch hC into @publisher_db, @subscriber, @subscriber_id,
  3371.             @subscriber_db
  3372.       end
  3373.     close hC
  3374.     DEALLOCATE hC
  3375.  
  3376.     select subscriber, 'delivered jobs' = sum(delivered_jobs),
  3377.        'undelivered jobs' = sum(undelivered_jobs),
  3378.        'delivery rate' = avg(delivery_rate),
  3379.        'delivery latency' = avg(delivery_latency)
  3380.        from #distcounters
  3381.        group by subscriber
  3382.  
  3383.     drop table #distcounters
  3384. GO
  3385.  
  3386. /* Set category bit to reflect MS objects */
  3387. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3388.     name = 'sp_MSdistribution_counters'
  3389. GO
  3390.  
  3391. /****************************************************************************/
  3392. PRINT ''
  3393. PRINT 'Creating Stored Procedure:  dbo.sp_MSremove_published_jobs'
  3394. PRINT ''
  3395. /****************************************************************************/
  3396. GO
  3397. CREATE PROCEDURE sp_MSremove_published_jobs
  3398. @publisher varchar(30),
  3399. @publisher_db varchar(30)
  3400.  
  3401. as
  3402.    declare @publisher_id smallint
  3403.    declare @retcode int
  3404.    declare @cmd1 varchar (255)
  3405.    declare @cmd2 varchar (255)
  3406.    declare @cmd3 varchar (255)
  3407.    declare @delcmd varchar (255)
  3408.    declare @job_command varchar (255)
  3409.    declare @file varchar (255)
  3410.    declare @table varchar (255)
  3411.  
  3412.  
  3413.    SET NOCOUNT ON
  3414.  
  3415.    /*
  3416.    ** Make sure the publisher is valid.
  3417.    */
  3418.    select @publisher_id = srvid from master..sysservers where
  3419.        srvname = @publisher
  3420.    if @publisher_id is NULL
  3421.    begin
  3422.       RAISERROR(14048, 16, -1, @publisher)
  3423.       return (1)
  3424.    end
  3425.  
  3426.    /*
  3427.    ** For each sync command that will be removed delete the sync file.
  3428.    */
  3429.    select @cmd1 = ''
  3430.    select @cmd2 = ''
  3431.    select @cmd3 = ''
  3432.    select @cmd1 = @cmd1 + 'declare hC1 scroll cursor for '
  3433.    select @cmd1 = @cmd1 + 'select jc.command from MSjobs j (index = ucMSjobs), MSjob_commands jc (index = ucMSjob_commands) '
  3434.    select @cmd1 = @cmd1 + 'where j.publisher_id = ' 
  3435.    select @cmd1 = @cmd1 + convert (varchar (10), @publisher_id) + ' and '
  3436.    select @cmd2 = @cmd2 + 'j.publisher_db = ''' + @publisher_db + ''' and '
  3437.    select @cmd2 = @cmd2 + 'jc.publisher_id = j.publisher_id '
  3438.    select @cmd3 = @cmd3 + 'and jc.publisher_db = j.publisher_db and '
  3439.    select @cmd3 = @cmd3 + 'jc.job_id = j.job_id and '
  3440.    select @cmd3 = @cmd3 + '(j.type = 3 or j.type = 4 or j.type = 5)'
  3441.  
  3442.    EXECUTE (@cmd1+@cmd2+@cmd3)
  3443.    OPEN hC1
  3444.    FETCH hC1 INTO @job_command
  3445.    WHILE (@@fetch_status <> -1)
  3446.       BEGIN
  3447.          EXEC @retcode = master..xp_sscanf @job_command, 'sync -t%s -d%s',
  3448.            @value1 = @table output, @value2 =@file output
  3449.          IF @retcode <> 0
  3450.      begin
  3451.         rollback transaction replcleanup
  3452.         CLOSE hC1
  3453.         DEALLOCATE hC1
  3454.             return (1)
  3455.      end
  3456.  
  3457.          EXEC @retcode = master..xp_sprintf @string = @delcmd output,
  3458.         @format = 'del %s', @value = @file
  3459.          IF @retcode <> 0
  3460.      begin
  3461.         CLOSE hC1
  3462.         DEALLOCATE hC1
  3463.             return (1)
  3464.      end
  3465.  
  3466.          EXEC master..xp_cmdshell @delcmd
  3467.  
  3468.          FETCH hC1 INTO @job_command
  3469.       END
  3470.    CLOSE hC1
  3471.    DEALLOCATE hC1
  3472.  
  3473.    /*
  3474.    ** Remove all but the last job of the publisher database jobs.  The last
  3475.    ** job is left incase the datatbase is enabled again. This will allow
  3476.    ** subscriber's last job ids to go unmodified.
  3477.    */
  3478.    delete from MSjobs where
  3479.     publisher_id = @publisher_id and
  3480.     publisher_db = @publisher_db and
  3481.     job_id <> (select max(job_id) from MSjobs j where
  3482.             j.publisher_id = @publisher_id and
  3483.             j.publisher_db = @publisher_db)
  3484.    if @@error <> 0
  3485.       return (1)
  3486.  
  3487.    /*
  3488.    ** Set transaction rid to -1, 0. This will set the published log to the
  3489.    ** last distributed transaction.
  3490.    */     
  3491.    update MSjobs set xactid_page = -1, xactid_row = 0 where
  3492.     publisher_id = @publisher_id and
  3493.     publisher_db = @publisher_db 
  3494.    if @@error <> 0
  3495.       return (1)
  3496.  
  3497.    /* Remove all the publisher database commands */
  3498.    delete from MSjob_commands where
  3499.       publisher_id = @publisher_id and
  3500.       publisher_db = @publisher_db
  3501.    if @@error <> 0
  3502.       return (1)
  3503.  
  3504.    /* Remove all the publisher database statuses */
  3505.    delete from MSsubscriber_status where
  3506.       publisher_id = @publisher_id and
  3507.       publisher_db = @publisher_db
  3508.    if @@error <> 0
  3509.       return (1)
  3510. GO 
  3511.  
  3512. /* Set category bit to reflect MS objects */
  3513. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3514.     name = 'sp_MSremove_published_jobs'
  3515. GO 
  3516.  
  3517.  
  3518. /****************************************************************************/
  3519. PRINT ''
  3520. PRINT 'Creating Stored Procedure:  dbo.sp_MSupdate_job'
  3521. PRINT ''
  3522. /****************************************************************************/
  3523. GO
  3524.  
  3525. CREATE PROCEDURE sp_MSupdate_job
  3526. @publisher_id smallint,
  3527. @publisher_db varchar (30),
  3528. @job_id int = 0,
  3529. @type tinyint = 0,
  3530. @xactid_page int = 0,
  3531. @xactid_row smallint = 0,
  3532. @xactid_ts binary(8) = 0
  3533. AS 
  3534.  
  3535. set nocount on
  3536. update MSjobs set type = @type, xactid_page = @xactid_page,
  3537.     xactid_row = @xactid_row, xactid_ts = @xactid_ts,
  3538.     entry_time = getdate()
  3539.     where
  3540.     publisher_id = @publisher_id and
  3541.     publisher_db = @publisher_db and
  3542.     job_id = @job_id
  3543. if @@error <> 0
  3544.    return(1)
  3545.  
  3546. GO
  3547.  
  3548. /* Set category bit to reflect MS objects */
  3549. UPDATE sysobjects SET category = category | 2 WHERE sysstat & 0xf = 4 AND
  3550.     name = 'sp_MSupdate_job'
  3551. go
  3552.  
  3553.  
  3554. /****************************************************************************/
  3555. print ''
  3556. print 'Create users'
  3557. print ''
  3558. /****************************************************************************/
  3559. GO 
  3560. if not exists (select * from sysusers where name = 'repl_subscriber')
  3561.     exec sp_adduser repl_subscriber
  3562. GO 
  3563. if not exists (select * from sysusers where name = 'probe')
  3564.     exec sp_adduser probe
  3565. GO 
  3566.  
  3567. /****************************************************************************/
  3568. print ''
  3569. print 'Granting privileges on distribution stored procedures'
  3570. print ''
  3571. /****************************************************************************/
  3572. GO 
  3573. grant execute on sp_MSadd_subscription to public
  3574. grant execute on sp_MSupdate_subscription to public
  3575. grant execute on sp_MSdrop_subscription to public
  3576. grant execute on sp_MSdistribution_counters to public
  3577. grant execute on sp_MShelp_subscriber_info to public
  3578. GO 
  3579.  
  3580. EXEC sp_configure 'allow updates', 0
  3581. GO
  3582.  
  3583. reconfigure with override
  3584. GO
  3585. -- - ----
  3586.