Click here to Skip to main content
15,889,216 members
Home / Discussions / Database
   

Database

 
GeneralRe: Ordering a linked list Pin
Colin Angus Mackay2-Oct-06 8:04
Colin Angus Mackay2-Oct-06 8:04 
GeneralRe: Ordering a linked list Pin
Colin Angus Mackay2-Oct-06 8:07
Colin Angus Mackay2-Oct-06 8:07 
QuestionLargest Data Typein SQL Server Pin
King Shez1-Oct-06 21:08
King Shez1-Oct-06 21:08 
AnswerRe: Largest Data Typein SQL Server Pin
albCode1-Oct-06 21:25
albCode1-Oct-06 21:25 
AnswerRe: Largest Data Typein SQL Server Pin
Mark Salsbery4-Oct-06 11:02
Mark Salsbery4-Oct-06 11:02 
Questionsql server 2005 Pin
amaneet29-Sep-06 20:21
amaneet29-Sep-06 20:21 
AnswerRe: sql server 2005 Pin
zhengdong jin30-Sep-06 7:32
zhengdong jin30-Sep-06 7:32 
QuestionReplication cursor [modified] Pin
Skanless29-Sep-06 16:18
Skanless29-Sep-06 16:18 
I am adding articles to be replicated but I would like to use a cursor to do it due the amount of tables it may take forever to select all from the wizard. I have written a cursor and I am having issues running it. Any suggestion will be greatly appreciated.

Cursor:

declare @tableName varchar(100)
declare c cursor for
select
table_name
from
information_schema.tables

where table_type = 'base table'

open c

fetch next from c into @tableName

while @@fetch_status = 0

begin

--print 'table name: ' + @tableName


--Adding the transactional articles
exec sp_addarticle @publication = N'One_Way_Trans', @article = @tableName , @source_owner = N'dbo', @source_object = @tableName, @destination_table = @tableName, @type = N'logbased', @creation_script = null, @description = null, @pre_creation_cmd = N'drop', @schema_option = 0x000000000000CEF3, @status = 16, @vertical_partition = N'false', @ins_cmd ='CALL sp_MSins_' + @tableName, @del_cmd = N'CALL sp_MSdel_' + @tableName, @upd_cmd = N'MCALL sp_MSupd_' + @tableName, @filter = null, @sync_object = null, @auto_identity_range = N'false'

fetch next from c into @tableName

end
close c
deallocate c


I am getting the following error when I run this script: Line 99: Incorrect syntax near '+'.

Here are the values I can not populate with @tableName.

@ins_cmd ='CALL sp_MSins_' + @tableName, @del_cmd = N'CALL sp_MSdel_' + @tableName, @upd_cmd = N'MCALL sp_MSupd_' + @tableName,


PS: I got the code below to do exactly what I want it to do but notice it is only printing the reults not executing the stored procedure.

declare @tableName varchar(100)
declare c cursor for

select
top 10 table_name
from
information_schema.tables

where table_type = 'base table'

open c

fetch next from c into @tableName

while @@fetch_status = 0

begin

--print 'table name: ' + @tableName


--Adding the transactional articles
print 'exec sp_addarticle @publication = N''One_Way_Trans'', @article = N ''' + @tableName + ''' , @source_owner = N''dbo'', @source_object = N''' + @tableName + ''', @destination_table = N'''+ @tableName + ''', @type = N''logbased'', @creation_script = null, @description = null, @pre_creation_cmd = N''drop'', @schema_option = 0x000000000000CEF3, @status = 16, @vertical_partition = N''false'', @ins_cmd = N''CALL sp_MSins_' + '' + @tableName + ''', @del_cmd = N''CALL sp_MSdel_' + ''+ @tableName + ''', @upd_cmd = N''MCALL sp_MSupd_' + '' + @tableName + ''', @filter = null, @sync_object = null, @auto_identity_range = N''false'''

fetch next from c into @tableName

end


close c



deallocate c






-- modified at 22:23 Friday 29th September, 2006

Greg

Coding makes the world go round!!!

AnswerRe: Replication cursor Pin
Skanless29-Sep-06 21:46
Skanless29-Sep-06 21:46 
QuestionT-SQL Syntax Pin
lakshmi_sri29-Sep-06 11:02
lakshmi_sri29-Sep-06 11:02 
AnswerRe: T-SQL Syntax Pin
zhengdong jin29-Sep-06 19:53
zhengdong jin29-Sep-06 19:53 
Questionshow records horizontally Pin
jlizardo29-Sep-06 5:32
jlizardo29-Sep-06 5:32 
AnswerRe: show records horizontally Pin
Elina Blank29-Sep-06 8:12
sitebuilderElina Blank29-Sep-06 8:12 
QuestionRe: show records horizontally Pin
jlizardo29-Sep-06 9:40
jlizardo29-Sep-06 9:40 
AnswerNot too hard Pin
Ennis Ray Lynch, Jr.2-Oct-06 15:51
Ennis Ray Lynch, Jr.2-Oct-06 15:51 
QuestionPlease help me Pin
honeyman_can29-Sep-06 3:50
honeyman_can29-Sep-06 3:50 
AnswerRe: Please help me Pin
JUNEYT29-Sep-06 4:12
JUNEYT29-Sep-06 4:12 
GeneralRe: Please help me Pin
honeyman_can29-Sep-06 4:24
honeyman_can29-Sep-06 4:24 
Questioni cannot seve E-mails Pin
abdelhameed8129-Sep-06 2:01
abdelhameed8129-Sep-06 2:01 
AnswerRe: i cannot seve E-mails Pin
Mike Dimmick29-Sep-06 4:52
Mike Dimmick29-Sep-06 4:52 
QuestionSQL Injection Pin
NICE TO MEET29-Sep-06 1:23
NICE TO MEET29-Sep-06 1:23 
AnswerRe: SQL Injection Pin
Colin Angus Mackay29-Sep-06 1:24
Colin Angus Mackay29-Sep-06 1:24 
QuestionDifference between DELETE, TRUNCATE, DROP Pin
NICE TO MEET29-Sep-06 1:20
NICE TO MEET29-Sep-06 1:20 
AnswerRe: Difference between DELETE, TRUNCATE, DROP Pin
Colin Angus Mackay29-Sep-06 1:23
Colin Angus Mackay29-Sep-06 1:23 
AnswerRe: Difference between DELETE, TRUNCATE, DROP Pin
Chris Meech29-Sep-06 7:29
Chris Meech29-Sep-06 7:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.