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