如何判断集合的包含问题:比如说,现在在A表中有两个字段x,y
如果x的值是21;2;51;14
    y的值是0;21;2;51;14
我如何判断x字段中的值y字段中,其中y 字段中的顺序不一定和x 中的顺序一样,
我如何判断?

解决方案 »

  1.   

    我在查询分析器里面用 intersect,不行啊,提示
    [Microsoft][ODBC SQL Server Driver]语法错误或违反访问规则
      

  2.   

    seelct count(*) as acount1 from a where x in (select y from a)
    seelct count(*) as acount2 from a 
    比较acount1和acount2就能知道是否包含了。
    acount2>acount1 不包含
    acount2<=acount1 包含
      

  3.   

    seelct count(x) as acount1 from a where x in (select y from a)
    seelct count(x) as acount2 from a 
    比较acount1和acount2就能知道是否包含了。
    acount2>acount1 不包含
    acount2<=acount1 包含
    试试看。
      

  4.   

    没人写我就写一函数吧
    --返回1表示包含,0不包含
    create function dbo.f_test(@x varchar(100),@y varchar(100))
    returns int
    as
    begin
    declare @str varchar(100)
    declare @flag int
    set @flag=1
    while charindex(';',@x)>0
    begin
    set @str=substring(@x,1,charindex(';',@x)-1)
    if charindex(';'+@str+';',';'+@y+';')=0
    begin
      set @flag=0
      break
    end
    set @x=right(@x,len(@x)-charindex(';',@x))
    end
    return @flag
    endgo
      

  5.   

    declare @sql varchar(4000),@str varchar(50)
    select @sql='select lie=',@str='a;b;c;d;'
    select @sql=@sql+''''+replace(@str,';',''' union all select ''')
    select @sql=left(@sql,len(@sql)-18)
    --print @sql
    exec(@sql)
      

  6.   

    根据上面个方法建立一个函数
    参数输入x,y得值
    分别得到x,y拆分得到的一个表
    再对此两表操作,x->a表,y->b表
    看b表是否包含a表
    是则返回一个数表示真
    反之否则返回一个数表示假