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)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 苗栗市| 宜章县| 霍林郭勒市| 惠安县| 梧州市| 克拉玛依市| 拜泉县| 金山区| 喀喇| 绵阳市| 雷州市| 云梦县| 电白县| 青海省| 林口县| 遂宁市| 永济市| 南漳县| 西贡区| 辽阳县| 平阳县| 洪雅县| 锡林浩特市| 即墨市| 离岛区| 平阳县| 永安市| 新建县| 儋州市| 辽阳县| 紫阳县| 丽江市| 雷州市| 太康县| 朔州市| 历史| 阳春市| 土默特右旗| 晋中市| 连城县| 康马县|