sql server 将A数据库中a表的数据插入B数据库中的b表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24313643/article/details/70255642


DECLARE @SortCode varchar(20);
DECLARE @NewsTitle VARCHAR(100);
DECLARE @ClassID VARCHAR(40);
DECLARE @Content varchar(8000);
DECLARE @Click INT;
DECLARE @CreatTime VARCHAR(20);
DECLARE @UpdateTime varchar(20);
DECLARE @ClassName varchar(100);
DECLARE @Categoryid int;


DECLARE contact_cursor CURSOR FOR
SELECT SortCode,NewsTitle,ClassID,Content,Click,CreatTime,ModifyDate FROM rm.dbo.DX_News WHERE DeleteMark = 1


OPEN contact_cursor


FETCH NEXT FROM contact_cursor
INTO @SortCode, @NewsTitle,@ClassID,@Content,@Click,@CreatTime,@UpdateTime


-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
   --PRINT 'Contact Name: ' + @FirstName + ' ' +  @LastName
   SELECT @ClassName = ClassCName FROM rm.dbo.DX_News_Class where ClassID = @ClassID;
   SELECT @Categoryid = id FROM dt_article_category where title = @ClassName;
   INSERT dt_article(channel_id,category_id,title,content,sort_id,click,[user_name],add_time,update_time) 
   VALUES(12,@Categoryid,@NewsTitle,@Content,@SortCode,@Click,'admin',@CreatTime,@UpdateTime);
   FETCH NEXT FROM contact_cursor
   INTO @SortCode, @NewsTitle,@ClassID,@Content,@Click,@CreatTime,@UpdateTime
END


CLOSE contact_cursor
DEALLOCATE contact_cursor
展开阅读全文

没有更多推荐了,返回首页