select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
insert into #proctext( procedure_text ) values ( N'create procedure ' + QUOTENAME(@dest_proc) + N' ')
select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
insert into #proctext( procedure_text ) values ( N'create procedure ' + QUOTENAME(@dest_proc) + N' ' )
select @cmd = N'if exists (select * from sysobjects where type = ''P'' and name = ''' + replace(@dest_proc, N'''', N'''''') + N''') drop proc ' + QUOTENAME(@dest_proc)
insert into #proctext(procedure_text) values( @cmd )
insert into #proctext(procedure_text) values( N'go' )
insert into #proctext( procedure_text ) values ( N'create procedure ' + QUOTENAME(@dest_proc) + N' ')
IF suser_sname(suser_sid()) <> @login_name AND is_srvrolemember('sysadmin') <> 1
AND is_member ('db_owner') <> 1
BEGIN
-- Only members of the sysadmin fixed server role, db_owner fixed database role or the creator of the subscription can change this subscription property.'
RAISERROR(21175, 11, -1)
RETURN (1)
END
-- Get pubid
declare @pubid int
select @pubid = pubid from sysarticles where artid = @artid
/* Get subscription type of the publication */
if not exists (select * from syspublications where
pubid = @pubid and
allow_dts = 1)
begin
RAISERROR(21178, 16, -1)
RETURN (1)
end
if @dts_package_location is null
select @dts_package_location_id = null
else IF LOWER(@dts_package_location) = N'distributor'
select @dts_package_location_id = 0
ELSE IF LOWER(@dts_package_location) = N'subscriber'
select @post_cmd = N'if exists (select * from sysobjects where name=N''syspublications'') if exists (select * from sysarticles where objid=object_id('''+ @qual_source_object + N''')) '
raiserror('sp_getqueuedrows(debug): could not locate table %s', 16, 1, @qualified_tabname)
return 1
end
--
-- current user should have SELECT permission on the table
--
if ( permissions(@tabid) & 0x1 = 0 )
begin
-- error
raiserror('sp_getqueuedrows(debug): current user does not have SELECT permission on table %s', 16, 1, @qualified_tabname)
return 1
end
--
-- make sure the table is participating in a active queued subscription
--
select @agent_id = agent_id
from dbo.MSsubscription_articles
where dest_table = @tablename and owner = @owner
if (@agent_id IS NULL)
begin
-- error
raiserror('sp_getqueuedrows(debug): table %s is not part of any active initialized queued subscription. Make sure your queued subscriptions are properly initialized', 16, 1, @qualified_tabname)
return 1
end
--
-- get the details for the subscription
--
select @publisher = publisher
,@publisher_db = publisher_db
,@publication = publication
,@update_mode = update_mode
,@queue_id = queue_id
,@failover_id = failover_mode
from dbo.MSsubscription_agents where id = @agent_id
if (@update_mode not in (2,3,4,5))
begin
-- error
raiserror('sp_getqueuedrows(debug): table %s is not part of any active initialized queued subscription. Make sure your queued subscriptions are properly initialized', 16, 2, @qualified_tabname)
return 1
end
--
-- If we are in Immediate Failover mode - no queued messages
--
if (@update_mode in (3,5) and (@failover_id = 0))
begin
--
-- do an empty select on the source table and return