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();
                  }


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

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


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 库车县| 广宁县| 库伦旗| 镇巴县| 芒康县| 平顶山市| 集安市| 大埔县| 德钦县| 开鲁县| 上高县| 盐池县| 安康市| 藁城市| 扎兰屯市| 醴陵市| 襄城县| 怀集县| 云安县| 筠连县| 申扎县| 邵阳县| 江阴市| 呼玛县| 永昌县| 宜君县| 淮安市| 利辛县| 博乐市| 沅陵县| 香河县| 龙陵县| 农安县| 册亨县| 东兴市| 景泰县| 沭阳县| 桑植县| 仁化县| 佛冈县| 子洲县|