select @aaa = count(*) from 表 where 标识=i ;
select @bbb = count(*) from (select distinct 物料名称 from 表 where 标识=i ) t
如果@aaa>@bbb那么存在重复

解决方案 »

  1.   

    public bool f(int i)
    {
        string sql = "select count(*) from Table where 物料名称 in (select 物料名称 from Table where 标识='"+i+"' )";
    执行sql根据结果返回true  or false 
    }
      

  2.   

    用存储过程:
    CREATE PROCEDURE [pro] 
    @id int,
    @Return bit out
    AS
    if exists(select * from (select 物料名称,count(物料名称) as Count from table where  标识 = @id) t where Count>1)
    set @Return = 1
    else
    set @Return = 0
      

  3.   

    CREATE PROCEDURE [pro] 
    @id int,
    @Return bit out
    AS
    if exists(select * from (select 物料名称,count(物料名称) as Count from table where  标识 = @id group by 物料名称 ) t where Count>1)
    set @Return = 1
    else
    set @Return = 0
      

  4.   


    select 1 from table where 标识=输入值 group by 物料名称 having(count(*)>1)
      

  5.   

    CREATE PROCEDURE [pro] 
    @id int,
    @Return bit output
    AS
    begin
    if exists(select 1 from table where 标识=@id group by 物料名称 having(count(*)>1))
    set @Return = 1
    else
    set @Return = 0
    end
      

  6.   

    select distinct count(*) as num from table where id = 1 group by 物料名称
    代码中循环一次
    if num > 1 return true;
      

  7.   

    没什么难的。
    select 标识, 物料名称, count(*) from 表
    where 标识=1(输入值)
    group by 标识, 物料名称
    having count(*)>1
    如有记录,就是真,没记录,就是假