如果只是查找Mrecode字段重复记录的话,这样写select * from  materielhead where Mrecode in (select Mreccode from materielhead  group by Mreccode having count(*)>1 )

解决方案 »

  1.   

    select Mreccode from materielhead  group by Mreccode having count(*)>1
      

  2.   

    create table #tkBoxPrice (  
    tkbox_no varchar(12),
    to_po_no varchar(20),
    stk_out_no varchar(12),
    Price decimal (18,4),
    uom_code varchar(5)  

    set @reccode=''
    declare Cur   cursor  for   
    select FrecCode from #tkbox
    where FrecCode<>''
    group by FrecCode
    open  Cur  
    fetch next from  Cur into @freccode
    while @@FETCH_STATUS =0  
     begin    
         if @reccode=''
             set @reccode=rtrim(@freccode)
         else
             set @reccode=@reccode+','+rtrim(@freccode)           
      
       fetch next from  Cur into @freccode
    end  
    close Cur  
    deallocate Cur insert into #tkBoxPrice
    exec [192.168.1.237].newfms.dbo.usp_cost_import_gms @reccode高手看看,上面的一段代码讲的是什么意思呀!请指教!
      

  3.   

    select Mreccode,count(Mreccode) from materielhead  group by Mreccode having count(Mreccode)>1
      

  4.   

    --建立虚拟表#tkBoxPrice 
    create table #tkBoxPrice (  
    tkbox_no varchar(12),
    to_po_no varchar(20),
    stk_out_no varchar(12),
    Price decimal (18,4),
    uom_code varchar(5)  

    --声明取不同并且不为空的表#tkbox的字段FrecCode的游标
    set @reccode=''
    declare Cur   cursor  for   
    select FrecCode from #tkbox
    where FrecCode<>''
    group by FrecCode
    --打开游标,循环取FrecCode字段值存入变量@reccode其中每个字段值间用‘,’分隔开
    open  Cur  
    fetch next from  Cur into @freccode
    while @@FETCH_STATUS =0  
     begin    
         if @reccode=''
             set @reccode=rtrim(@freccode)
         else
             set @reccode=@reccode+','+rtrim(@freccode)           
      
       fetch next from  Cur into @freccode
    end  
    --关闭游标
    close Cur  
    deallocate Cur 
    --传参数@reccode调用存储过程并将结果保存到表#tkBoxPrice(这种用法第一次见)
    insert into #tkBoxPrice
    exec [192.168.1.237].newfms.dbo.usp_cost_import_gms @reccode
      

  5.   

    select Mreccode from materielhead  group by Mreccode having count(Mreccode)>1
      

  6.   

    如果只查询重复的mreccode:
    select Mreccode from materielhead  group by Mreccode having count(Mreccode)>1
    Select * From Mreccode Where Exists(Select 1 From materielhead  group by Mreccode having Count(Mreccode)>1)
      

  7.   

    如果只查询重复的mreccode,支持 Frewin(Frewin)
    如果查询所有的列相同
    select * from table1 where column1+column2+...
    in(select column1+column2+... from table1 
    group by column1,column2,...
    having count(*)>1)
      

  8.   

    如果需要手工转换类型,用convert即可
      

  9.   

    select Mreccode from materielhead  group by Mreccode having count(Mreccode)>1
      

  10.   

    Select Mreccode,count(Mreccode) from materielhead  group by Mreccode having count(Mreccode)>1