SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_reinitsubscription multiple subscribers


sp_reinitsubscription multiple subscribers

Author
Message
dmike
dmike
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 95
we are trying to target the re-initialization of a subscription at certain subscribers at the same time.

the following has been successful for a single subscriber:
sp_reinitsubscription @publication = 'my_publication',
@subscriber = 'subscriber1', @destination_db = 'dest_dbase',
@invalidate_snapshot = 1

substituting 'all' works for all the subscribers:
sp_reinitsubscription @publication = 'my_publication',
@subscriber = 'all', @destination_db = 'dest_dbase',
@invalidate_snapshot = 1

is there a syntax that allows for specifying multiple subscriptions but not all - say defining 10 subscriptions out of 20?

any help would be appreciated.
Dennis Post
Dennis Post
SSC Eights!
SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)SSC Eights! (999 reputation)

Group: General Forum Members
Points: 999 Visits: 547
Hi,

Depending on your criteria you could do something like:
DECLARE   @SQL Varchar(MAX)
SELECT @SQL = ''

--SELECT P.Name PubName, S.SrvName SubScriber, S.Dest_DB
SELECT @SQL = @SQL +
'sp_reinitsubscription @publication = '''+P.Name+
''', @subscriber = '''+S.SrvName+
''', @destination_db = '''+S.Dest_DB+
''', @invalidate_snapshot = 1' + CHAR(13)
FROM [DBO].[sysPublications] P
INNER JOIN [DBO].[sysArticles] A ON P.PubID = A.PubID
INNER JOIN [DBO].[sysSubscriptions] S ON A.ArtID = S.ArtID
WHERE S.SrvName <> ''
AND S.SrvName NOT IN ('List', 'of', 'subscribers', 'to', 'filter', 'out')
GROUP BY P.Name, S.SrvName, S.Dest_DB
PRINT @SQL
--EXEC (@SQL)



Better yet, create a table of subscriber servers you wish to reinitiate and join to it instead of using IN ('blah', 'blah')

If more complex requirements are needed, alter the statement to use in a cursor.

Hope this helps.



For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search