所有文章的EXEC sp_changemergearticle

时间:2014-12-02 13:07:30

标签: sql-server stored-procedures replication

有没有办法可以同时更改复制中所有文章的属性?

所以而不是:

EXEC sp_changemergearticle 
@publication = 'MyPublication', 
@article = 'MyArticle', 
@property = 'published_in_tran_pub', 
@value = 'true';

EXEC sp_changemergearticle 
@publication = 'MyPublication', 
@article = 'MyArticle1', 
@property = 'published_in_tran_pub', 
@value = 'true';

EXEC sp_changemergearticle 
@publication = 'MyPublication', 
@article = 'MyArticle2', 
@property = 'published_in_tran_pub', 
@value = 'true';

EXEC sp_changemergearticle 
@publication = 'MyPublication', 
@article = 'MyArticle3', 
@property = 'published_in_tran_pub', 
@value = 'true';

我想在一个查询中为所有文章更改属性@published_in_tran_pub。类似的东西:

EXEC sp_changemergearticle 
@publication = 'MyPublication', 
@article = 'ALL ARTICLES', 
@property = 'published_in_tran_pub', 
@value = 'true';

所以我想通过一个语句更改所有文章的@published_in_tran_pub属性。

提前致谢

1 个答案:

答案 0 :(得分:0)

对,

我可能有这个错误(再次) - 但是看起来我不知道什么比你想要调用很多东西 - 你可以循环你的文章并将它们传递给你的sproc;

-- I presume you can get a list of distinct Articles - you dont have to use 
-- a tmp table if they already exist - use that table instead

SELECT DISTINCT ROW_NUMBER() OVER (ORDER BY Article) as Row_ID,
                Article
INTO #Tmp
FROM MyArticleTable -- Dont know what this is called
WHERE publication = @publication -- only pick the articles you want to use for this sproc call

DECLARE @i int = 1
DECLARE @currentArticle varchar(max) 

WHILE @i <= (SELECT COUNT(*) FROM #Tmp)
BEGIN 
    SET @currentArticle = (SELECT Article FROM #Tmp WHERE Row_ID = @i)
    EXEC sp_changemergearticle 
    @publication = 'MyPublication', 
    @article = @currentArticle, 
    @property = 'published_in_tran_pub', 
    @value = 'true'

SET @i = @i+ 1

END