CREATE PROCEDURE saveend @abc intAS
declare @who varchar(20)
declare @word varchar(8000)
declare @s varchar(100)
declare @roomid int
fetch next from  abc  into @who
    WHILE @@FETCH_STATUS = 0
    begin
     declare   ab  cursor  for select roomid,who+'对'+towho+content as content1 from  (select  distinct(who)  from  chttmp_1) abc where (who=@who or towho=@who)
      open ab
      fetch next from ab into @roomid,@s
      while @@FETCH_STATUS = 0
      begin
       set  @word = isnull(@word,'') + isnull(@s,'') + "<br>"
       set @s = ' '
fetch next from ab into @roomid, @s
      end
       close ab
       deallocate ab
insert into chat_record(roomid,who,content) values(@roomid,@who,@word)
set @word = " "

     fetch next from  abc  into @who
   End
      close abc 
      deallocate abc
GO

解决方案 »

  1.   

    上面那段我想会给大家引起误会,我把程序改了一下,更利于大家理解
    大家看这段存储过程,为什么检查语法时总说错误137,必须声明变量@lingshi,可我已经声明了@lingshi了,在saveend后面声明的,请大家帮帮忙
    CREATE PROCEDURE saveend @lingshi intAS
    declare @who varchar(20)
    declare @word varchar(8000)
    declare @s varchar(100)
    declare @roomid int
    declare   abc  cursor  for
    select  distinct(who)  from  @lingshi
    open   abc 
    fetch next from  abc  into @who
        WHILE @@FETCH_STATUS = 0
        begin
          declare   ab  cursor  for select roomid,who+"对"+towho+content as content1 from  @lingshi where (who=@who or towho=@who)
          open ab
          fetch next from ab into @roomid,@s
          while @@FETCH_STATUS = 0
          begin
           set  @word = isnull(@word,'') + isnull(@s,'') + "<br>"
           set @s = ' '
    fetch next from ab into @roomid, @s
          end
           close ab
           deallocate ab
    insert into chat_record(roomid,who,content) values(@roomid,@who,@word)
    set @word = " "

         fetch next from  abc  into @who
       End
          close abc 
          deallocate abc
    GO
      

  2.   

    上面的程序有错误我又修改了一些,请大家看下面的,错误还是一样的
    CREATE PROCEDURE saveend @lingshi  varchar(40)
    AS
    declare @who varchar(20)
    declare @word varchar(8000)
    declare @s varchar(100)
    declare @roomid int
    declare   abc  cursor  for
    select  distinct(who)  from @lingshi
    open   abc 
    fetch next from  abc  into @who
        WHILE @@FETCH_STATUS = 0
        begin
          declare   ab  cursor  for select roomid,who+"对"+towho+":"+content as content1 from @lingshi where (who=@who or towho=@who)
          open ab
          fetch next from ab into @roomid,@s
          while @@FETCH_STATUS = 0
          begin
           set  @word = isnull(@word,'') + isnull(@s,'') + "<br>"
           set @s = ' '
    fetch next from ab into @roomid, @s
          end
           close ab
           deallocate ab
    insert into chat_record(roomid,who,content) values(@roomid,@who,@word)
    set @word = " "

         fetch next from  abc  into @who
       End
          close abc 
          deallocate abc
    GO
    就是提示lingshi未定义