Sql Server while循环时配合使用游标及对远程数据库的操作

     declare  @table   table(
	[CITY_NAME] [varchar](50) NULL,
	[REGION] [varchar](50) NULL,
	)
	
	DECLARE @CITY_NAME VARCHAR(50);
	DECLARE @REGION VARCHAR(50);
	DECLARE @DATE VARCHAR(6);
	SET @DATE='2012'
	DECLARE EVALUATE_CURSOR CURSOR FOR select CITY_NAME,REGION from [DB_APP_EDC].[dbo].[INDEX_MERGE_HOME_MAIN];
	OPEN EVALUATE_CURSOR;
	FETCH NEXT FROM EVALUATE_CURSOR INTO @CITY_NAME,@REGION;
	WHILE @@FETCH_STATUS = 0
	begin 
		insert into @table exec [DB_APP_EDC].[dbo].[存储过程名称]	@CITY_NAME,@REGION,@DATE
		FETCH NEXT FROM EVALUATE_CURSOR INTO @CITY_NAME,@REGION;
	END;
	
	INSERT INTO [172.18.11.91].[DB_APP_EDC_RESULT].[dbo].[TB_CITY_EVALUATE]
	select NEWID() as CITY_EVALUATE_ID,CITY_NAME,REGION,getdate() as EVALUATE_DATE from @table
CLOSE EVALUATE_CURSOR; DEALLOCATE EVALUATE_CURSOR;

  

posted @ 2013-03-29 09:45  V.Wang  阅读(300)  评论(0编辑  收藏  举报