当前位置: 代码迷 >> ASP.NET >> 关于SQL语句,求救解决方案
  详细解决方案

关于SQL语句,求救解决方案

热度:5584   发布时间:2013-02-26 00:00:00.0
关于SQL语句,求救
declare   @i   int
set   @i=0
while   @i <(select   count(speak_id)   from   web..bbs_content)
begin

      insert   into   FORUM_DOC(FR_NO,FR_ID,usr)   SELECT   TOP   10   A.SPEAK_ID,A.BBSMOD_ID,A.SPEAKER_ID   From   web..bbs_content   AS   A   where   A.speak_id   not   in
(SELECT   TOP   @i   B.speak_id   FROM   web..bbs_content   AS   B   ORDER   BY   B.speak_id)

      set   @i=@i+1
end

这个时候(SELECT   TOP   @i   B.speak_id   FROM   web..bbs_content   AS   B   ORDER   BY   B.speak_id)
里的变量@i找不到了,为什么呢?

------解决方案--------------------------------------------------------
什么问题没看清除,但用这个应该可以解决问题

原SQL语句改成:
exec ( 'insert into FORUM_DOC(FR_NO,FR_ID,usr) SELECT TOP 10 A.SPEAK_ID,A.BBSMOD_ID,A.SPEAKER_ID From web..bbs_content AS A where A.speak_id not in
(SELECT TOP '+@i+ ' B.speak_id FROM web..bbs_content AS B ORDER BY B.speak_id) ')
  相关解决方案