update publish set contentid= (selecttop1 articles.contentid from articles where articles.articleID=publish.objectID ) --where publish.objectid=@objectID
SET NOCOUNT ON DECLARE@contentIDint declare@objectIDint declare@countnumberint set@countnumber=0 DECLARE publish_cursor CURSORFOR select a.contentid,a.articleID from publish p innerjoin articles a on a.articleID=p.objectID where objectid>0and p.contentid<> a.contentid and (p.cellid=160or cellid=138) OPEN publish_cursor
WHILE@@FETCH_STATUS=0 BEGIN print@contentID print@objectID
--修改记录 update publish set ContentID=@contentIDwhere objectid=@objectID --修改结束 FETCHNEXTFROM publish_cursor into@contentID,@objectID
END CLOSE publish_cursor DEALLOCATE publish_cursor
GO
select p.publishid,p.contentid,a.contentid,p.objectID,a.articleID from publish p innerjoin articles a on a.articleID=p.objectID where objectid>0and p.contentid<> a.contentid and (p.cellid=160or cellid=138) go
-- update publish set contentid=0 where (cellid=160 or cellid=138) -- select * from publish p where ( p.cellid=160 or cellid=138)
在没有更好的办法呢? 其实还可以这样:
update publish set contentid= a.contentid from articles a innerjoin publish p on p.objectID=a.articleID where cellid=138
-- select * from publish where cellid=138 -- update publish set contentid=0 where cellid=138