在存储过程中select i from A 定义个@j 
如果@j不在查处来的i中
set @j=1咋写?这要在C#中我会,就是datatabel =select i from A where i!=j
if(datatable.rows.count<=0)
{
  j=1
}但是在SQL存储过程中,如何找一个类似于datatable的变量来存取select i from A呢?怎么判断datatable.rows.count呢?注意: 是在存储过程中写

解决方案 »

  1.   


    declare @tb table(i nvarchar(10))insert @tb 
    select 'a' union all
    select 'b' union all
    select 'c'declare @j nvarchar(10)
    set @j = 'd'if((select count(1) from @tb where i = @j) <= 0)
    set @j = '1'select @j
    /*
    --结果
    1
    */
    set @j = 'a'if((select count(1) from @tb where i = @j) <= 0)
    set @j = '1'select @j
    /*
    --结果
    a
    */
    是不是 你要的结果...
      

  2.   

    DECLARE @j varchar(4)
    SET @j = 'aa'
    select @j = (case when a.Cnt = 0 then 1 else @j end) from ( select Cnt = count(1) from @tb where i = @j) a
      

  3.   


    对  你的意思就是用COUNT来解决,明白了 谢谢