1 select count(*) from table1 where ...
2
create proc delrec
AS
BEGIN
  select distinct * into #t1 from table1
  delete a
  from table1 a,#t1 b
  where a.field1=b.field1 and a.field2=b.field2 and ...
        and a.fielddatetime>b.fielddatetime
END

解决方案 »

  1.   

    1.select count(*) from tablename where ....
    2.select distinct * into #temptable from tablename
      drop table tablename
      go
      select * into tablename from #tamptable
      drop table #temptable
      go
      

  2.   

    2 如果去掉重复的整个记录
    create proc delrec
    AS
    BEGIN
      select * into #t1 from table1 group by field1,...fieldn
      trancate table table1 
      insert into table1 select * from #t1
    END
      

  3.   

    使用select count(*) from tablename where ....时发现一个问题,select count(*) from tablename where id=101110 and tim like '[2002-6-1]%'
    后统计的数字是 2000,而把and tim like '[2002-6-1]%'去掉后检索全表数字还是 2000,不知为什么?
      

  4.   

    如果tim是datatime字段,不能用like查询:select count(*) from tablename where id=101110 and tim >= '2002-6-1'
    and tim < '2002-7-1'
    查询所有2002年6月select count(*) from tablename where id=101110 and tim >= '2002-6-1'
    and tim < '2002-6-2'
    查询所有2002年6月1日select count(*) from tablename where id=101110 and tim >= '2002-6-10'
    and tim < '2002-6-20'
    查询所有2002年6月中旬
    不知道你的原意是哪一个!