查找字段记录最长字符数.sql 823 B

1234567891011121314151617181920212223242526
  1. /************************************************************************/
  2. /*
  3. 程序编写: Jeff
  4. 版 本: V 1.0
  5. 建立日期: 2015-06-02
  6. 功能说明: 查找字段记录最长字符数;
  7. 备 注:
  8. 修改日期:
  9. 修改说明:
  10. */
  11. /************************************************************************/
  12. use [db]
  13. declare @len int
  14. select @len = max(len([count])) from dindansp3
  15. select * from dindansp3 where len([count]) = @len
  16. --删除[lonindata]表中多余的重复记录,并创建约束;
  17. use [db]
  18. select identity(int,1,1) as autoid, * into #temp1 from [lonindata]
  19. select min(autoid) as autoid into #temp2 from #temp1 group by [no],[datetime]
  20. truncate table [lonindata]
  21. insert into [db].[dbo].[lonindata]([no],[datetime]) select [no],[datetime] from #temp1 where autoid in(select autoid from #temp2) order by [no]
  22. drop table #temp1
  23. drop table #temp2