select @tempcate=物品类别,@mycate=我的类别,@property=属性,@wpzr=物品主人 from products where id in(select valueid from dbo.f_split(@wpid,',')) and 物品主人=@wponwer
我怎么把这里取出来的记录作如下处理啊,类似于ASP里的循环
Set @i=0
WHILE @i < len(@tempcate)/4 
BEGIN 
Set @i =@i +1 
Update Category set pcount=pcount-1 Where CateCode=Substring(@tempcate,1,@i*4) --老类别上减一
END
UPdate Cate_Property_value set pcount=pcount-1 where valueid in(select valueid from dbo.f_split(@property,','))
update mycategory set pcount=pcount-1 where username=@wpzr and catename=@mycate

解决方案 »

  1.   

    就是在存储过程里
    我要取记录集
    这里是:select @tempcate=物品类别,@mycate=我的类别,@property=属性 from products where id in(select valueid from dbo.f_split(@wpid,',')) 
    然后对取出来的各条记录进行处理,循环刚才取出的记录集update mycategory set pcount=pcount-1 where username=@wpzr and catename=@mycate
    就是在存储过程里实现类似于ASP里的
    sql="select id from product"
    set rs=conn.execute(sql)
    if not rs.eof 
      conn.execute("insert into ttt (pid)values("&rs(0)&")")
    end if
      

  2.   

    用游标
    declare @atempcate varchar(100),@mycate varchar(100),@property varchar(100),@wpzr varchar(100)declare cur cursor for
    select 物品类别,我的类别,属性,物品主人 from products where id in(select valueid from dbo.f_split(@wpid,',')) and 物品主人=@wponwer
    fetch next into @atempcate ,@mycate ,@property ,@wpzr from cur
    while @@fetch_status=0
    begin
    Set @i=0
    WHILE @i < len(@tempcate)/4 
    BEGIN 
    Set @i =@i +1 
    Update Category set pcount=pcount-1 Where CateCode=Substring(@tempcate,1,@i*4) --老类别上减一
    END
    UPdate Cate_Property_value set pcount=pcount-1 where valueid in(select valueid from dbo.f_split(@property,','))
    update mycategory set pcount=pcount-1 where username=@wpzr and catename=@mycate
    fetch next into @atempcate ,@mycate ,@property ,@wpzr from cur
    end
    close cur
    deallocate cur
      

  3.   

    游標阿
    declare cur_test cursor for
    select 物品类别,我的类别,属性 from products where id in(select valueid from dbo.f_split(@wpid,',')) 
    open cur_test
    fetch next into @tempcate,@mycate,@property
    while @@fetch_status = 0
    bgein
    Set @i=0
    WHILE @i < len(@tempcate)/4 
    BEGIN 
    Set @i =@i +1 
    Update Category set pcount=pcount-1 Where CateCode=Substring(@tempcate,1,@i*4) --老类别上减一
    END
    UPdate Cate_Property_value set pcount=pcount-1 where valueid in(select valueid from dbo.f_split(@property,','))
    update mycategory set pcount=pcount-1 where username=@wpzr and catename=@mycate
    fetch next into @tempcate,@mycate,@property
    end
    close cur_test
    DEALLOCATE cur_test
    這個意思?
      

  4.   

    chuifengde(树上的鸟儿) 会出错消息 154,级别 15,状态 3,过程 wpback,第 21 行
    在 游标声明 中不允许使用 变量赋值。
    消息 156,级别 15,状态 1,过程 wpback,第 21 行
    关键字 'and' 附近有语法错误。
    消息 156,级别 15,状态 1,过程 wpback,第 22 行
    关键字 'from' 附近有语法错误。