查询前3个月每月是否有数据 需求:页面Dropdownlist 中绑定的时间是年-月,这个年月根据数据库中是否有数据显示。如果当月有数据,就绑定2009-3,如果2月份也有数据再添加2009-2,没有数据的月份就不显示。数据库中有时间存入。有什么好的方法,查询最近3月的每月数据,来给dropdownlist中添加年月。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写个function判断一下.有就添加进去. select top 3 convert(varchar(7),date,120) from table group by date having count(content)>=1 order by date desc 寫錯了~~~select top 3 convert(varchar(7),date,120) from table group by convert(varchar(7),date,120) order by date desc select convert(char(7),dateField,120) as ym from tableName group by convert(char(7),dateField,120) select * from table where datediff(d,convert(varchar(7),getdate(),120),convert(varchar(7),你的时间列名,120))>2 月是mselect * from table where datediff(m,convert(varchar(7),getdate(),120),convert(varchar(7),你的时间列名,120))>2 麻烦点的话,你就在数据库里查时间,如果这个月有数据,那么你查出来的表的行就不为0,如果没有数据,那么你查出来的表的行就为0gridview.rows.count(),好像是这样,代码是手写的,如果为0那就不绑定,但是这样很麻烦,具体简单点的我在想下看 select convert(char(7),dateField,120) as ym from tableName group by convert(char(7),dateField,120)select convert(char(7),dateField,120)as ym from tableName Group by covert(char(7),dateField,120)没有把语句写出来哦!差别好大呵呵!还是谢谢楼主!学习 各位推荐一个“日期时间”控件,“My97DatePicker”在IE8出问题。 关于DAL层方法问题求高人帮忙看下。 有哪位知道google的translate的原理 急急急 大家当初找到第一个工作时技术怎么样?大家说说吧 SQL语句的参数问题???? 关于水晶报表参数默认值!!! DropDownList绑定的问题 请问有没有讲述ASP.NET站点编程的书籍下载,C#的 请教(急)网页分页显示 SoapHeader的问题 【撒分】简单的页面传值问题ASP.NET
有就添加进去.
select top 3 convert(varchar(7),date,120) from table group by date having count(content)>=1 order by date desc
月是m
select * from table where datediff(m,convert(varchar(7),getdate(),120),convert(varchar(7),你的时间列名,120))>2
gridview.rows.count(),好像是这样,代码是手写的,如果为0那就不绑定,但是这样很麻烦,具体简单点的我在想下看
select convert(char(7),dateField,120)as ym from tableName Group by covert(char(7),dateField,120)没有把语句写出来哦!差别好大呵呵!还是谢谢楼主!学习