public static string StructSql(int startYear, int startMonth, int endYear, int endMonth)
        {
            StringBuilder tempSql = new StringBuilder();
            DateTime dtStart = new DateTime(startYear, startMonth, 1);
            DateTime dtEnd = new DateTime(endYear, endMonth, 1);
            TimeSpan ts = dtEnd - dtStart;
            int tempStartYear = startYear;
            int tempStartMonth = startMonth;
            if (ts.TotalDays > 25)
            {

                for (int i = startMonth; i <= 12; i++)
                {
                    if (i == startMonth && tempStartYear == startYear)
                        tempSql.AppendFormat("select '{0}' as A,'{1}' as B from dual\n", tempStartYear.ToString(), tempStartMonth.ToString());
                    else
                        tempSql.AppendFormat(" union all select '{0}' as A,'{1}' as B from dual\n", tempStartYear.ToString(), tempStartMonth.ToString());


                 
                    if (tempStartYear >= endYear && tempStartMonth >= endMonth)
                        break;

                    if (i == 12)
                    {
                        tempStartYear++;
                        i = 0;
                        tempStartMonth = 0;

                    }

                    tempStartMonth++;
                 
                }
            }
            else
            {
               // Page.RegisterStartupScript("message", "<script type='text/javascript'>alert('查询的截至时间小于一个月不能查询!')</script>");
                return "";
                //Response.End();
            }
            return tempSql.ToString();
        }

posted on 2010-09-03 16:19 sanmao 阅读(100) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜