1、查找数据库中用到表tb_blackname的表、存储过程等: select a.text,b.name,b.xtype from dbo.syscomments a,dbo.sysobjects b where a.id=b.id and PATINDEX('%tb_blackname%', a.text)>0 order by xtype
2、对某个字段按区间统计条数 select case when buildfeecountructfee<1000 then '0-1000' when buildfeecountructfee>=1000 and buildfeecountructfee <5000 then '1000-5000' when buildfeecountructfee>=5000 and buildfeecountructfee <10000 then '5000-10000' else '10000以上' end,count(*) from tb_buildfee group by case when buildfeecountructfee<1000 then '0-1000' when buildfeecountructfee>=1000 and buildfeecountructfee <5000 then '1000-5000' when buildfeecountructfee>=5000 and buildfeecountructfee <10000 then '5000-10000' else '10000以上' end 3、对某个时间字段,按周期统计 --周期(年) select devicename,year(DeviceFinishDate),count(*) from tb_device group by devicename, year(DeviceFinishDate) --周期(年、月) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),month(DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),month(DeviceFinishDate)) --周期(年、季度) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(qq,DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(qq,DeviceFinishDate)) --周期(年、周) select devicename,convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(wk,DeviceFinishDate)),count(*) from tb_device group by devicename, convert(varchar(4),year(DeviceFinishDate))+'-'+convert(varchar(2),datepart(wk,DeviceFinishDate))