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('查詢的截至?xí)r間小于一個月不能查詢!')</script>");
                          return "";
                          //Response.End();
                      }
                      return tempSql.ToString();
                  }


          文章來源:http://www.cnblogs.com/wangdetian168/archive/2010/09/03/1817163.html
          posted on 2010-09-28 10:47 sanmao 閱讀(224) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金寨县| 福清市| 寻甸| 平度市| 公主岭市| 正镶白旗| 门头沟区| 宜昌市| 怀柔区| 郎溪县| 堆龙德庆县| 华坪县| 凯里市| 高邑县| 娱乐| 清水河县| 沅陵县| 洪雅县| 赤壁市| 三门县| 天台县| 沧源| 城口县| 苍梧县| 临安市| 浑源县| 浙江省| 泸水县| 太和县| 克什克腾旗| 墨玉县| 白水县| 蒙城县| 龙门县| 宁蒗| 垣曲县| 江都市| 东至县| 周至县| 彭阳县| 天水市|