Contents



create table #temp(rs varchar(8000))

declare 
	@str varchar(8000)
,	@i int

set @i = 1
set @str = 'cd "C:\Program Files\Microsoft SQL Server\90\COM"'
insert #temp values(@str)

-- =============================================
-- Declare and using a READ_ONLY cursor
-- =============================================
DECLARE cur CURSOR
READ_ONLY
FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

DECLARE @name varchar(40)
OPEN cur

FETCH NEXT FROM cur INTO @name
WHILE (@@fetch_status <> -1)
BEGIN
	IF (@@fetch_status <> -2)
	BEGIN
		if @i = 1
		begin
			set @str = 'tablediff -sourceserver "localhost\sql2000" -sourcedatabase "MuOnlineKor" -sourcetable "' + @name + '" -destinationserver "" -destinationdatabase "MuOnline" -destinationtable "' + @name + '" -q > c:\rs.txt'
			insert #temp values(@str)
		end else
		begin
			set @str = 'tablediff -sourceserver "localhost\sql2000" -sourcedatabase "MuOnlineKor" -sourcetable "' + @name + '" -destinationserver "" -destinationdatabase "MuOnline" -destinationtable "' + @name + '" -q >> c:\rs.txt '
			insert #temp values(@str)
		end
		--insert #temp exec master..xp_cmdshell @str

		set @i = @i + 1
	END
	FETCH NEXT FROM cur INTO @name
END

CLOSE cur
DEALLOCATE cur

select * from #temp
drop table #temp