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

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