大体语句是这个样子的。。
declare @i int
select @i = ID From Table1 Where ID = 1if(@i=1)
.......
.......
然后使用if语句比较时会产生错误
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。
语句已终止。 改成如下赋值同样不得解决set @i = (select top 1 ID From Table1 Where ID = 1)知道的麻烦解答下吧。

解决方案 »

  1.   

    ALTER PROCEDURE dbo.TP_ProductList @productclassid int,
    @start int,
    @end intAS
    set nocount on

    declare @Tables table(id int identity(1,1),nid int)
    set rowcount @End

    if(@productclassid=0)
    Begin
    insert into @Tables(nid) 
    select ID from T_Product order by ID desc
    End
    else
    begin
    declare @i int
    set @i = (select max(fatherid) from T_ProductClass where id=@productclassid)

    if(@i=0)
    begin
    insert into @Tables(nid) 
    select ID from T_Product 
    where productclassid = (select id from T_ProductClass where fatherid=0) 
    order by ID desc
    end

    else
    begin
    insert into @Tables(nid) 
    select ID from T_Product 
    where productclassid=@productclassid 
    --and productclassid = (select fatherid from T_ProductClass where id=@productclassid) 
    order by ID desc
    end

    end
    select *
    From T_Product O,@Tables t 
    where 
    O.ID=t.nid And t.id between @Start And @End order by t.id RETURN
    --select fatherid from T_ProductClass where id=7,1
      

  2.   

    单步执行
    参数值:1   1    11
    @i 值 0 
    运行到if(@i=0)语句时直接跳出条件判断
      

  3.   

    set @i = (select max(fatherid) from T_ProductClass where id=@productclassid) 这句是不是会返回两行以上的数据?
      

  4.   

    还有if(@i=0)
    begin
    insert into @Tables(nid)
    select ID from T_Product
    where productclassid = (select id from T_ProductClass where fatherid=0)
    order by ID desc
    end 
      

  5.   

    select ID from T_Product
    where productclassid = (select id from T_ProductClass where fatherid=0)
      

  6.   

    按照这样子写应该只会返回一行并且ID是唯一的,用ID做条件返回的行数也应该是一行,可是就是不能比较