我需要找到季度startQ1,startQ2等的开始。运行一个需要6个查询参数的查询。我真的不知道这样做的方法。所以如果我可以使用日历来发现今天是March1st(startq1)我不想用q1数组运行查询...希望更清楚。
Calendar cal = Calendar.getInstance();
java.sql.Date startQ1 = java.sql.Date.valueOf("2014-03-01");
java.sql.Date startQ2 = java.sql.Date.valueOf("2014-06-01");
java.sql.Date startQ3 = java.sql.Date.valueOf("2014-09-01");
java.sql.Date startQ4 = java.sql.Date.valueOf("2014-12-01");
java.sql.Date [][] q1 = new java.sql.Date[3][2];
q1[0][0] = java.sql.Date.valueOf("2014-07-01");
q1[0][1] = java.sql.Date.valueOf("2014-09-30");
q1[1][0] = java.sql.Date.valueOf("2014-10-01");
q1[1][1] = java.sql.Date.valueOf("2014-12-31");
q1[2][0] = java.sql.Date.valueOf("2015-04-01");
q1[2][1] = java.sql.Date.valueOf("2015-06-30");
java.sql.Date [][] q2 = new java.sql.Date[3][2];
q2[0][0] = java.sql.Date.valueOf("2014-10-01");
q2[0][1] = java.sql.Date.valueOf("2014-12-31");
q2[1][0] = java.sql.Date.valueOf("2015-01-01");
q2[1][1] = java.sql.Date.valueOf("2015-03-31");
q2[2][0] = java.sql.Date.valueOf("2015-07-01");
q2[2][1] = java.sql.Date.valueOf("2015-09-30");
java.sql.Date [][] q3 = new java.sql.Date[3][2];
q3[0][0] = java.sql.Date.valueOf("2015-01-01");
q3[0][1] = java.sql.Date.valueOf("2015-03-31");
q3[1][0] = java.sql.Date.valueOf("2015-04-01");
q3[1][1] = java.sql.Date.valueOf("2015-06-30");
q3[2][0] = java.sql.Date.valueOf("2015-10-01");
q3[2][1] = java.sql.Date.valueOf("2015-12-31");
java.sql.Date [][] q4 = new java.sql.Date[3][2];
q4[0][0] = java.sql.Date.valueOf("2015-04-01");
q4[0][1] = java.sql.Date.valueOf("2015-06-30");
q4[1][0] = java.sql.Date.valueOf("2015-07-01");
q4[1][1] = java.sql.Date.valueOf("2015-09-30");
q4[2][0] = java.sql.Date.valueOf("2016-01-01");
q4[2][1] = java.sql.Date.valueOf("2016-03-31");
if(cal.getTime() == startQ1) { // I know can't actually test this way.
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 2; j++) {
ps.setDate(1, q1[i][j]);
ps.setDate(2, q1[i][j]);
ps.setDate(3, q1[i][j]);
ps.setDate(4, q1[i][j]);
ps.setDate(5, q1[i][j]);
ps.setDate(6, q1[i][j]);
}
}
}
以下是查询:
PreparedStatement ps=conn.prepareStatement("select distinct b.new_tagID,"
+ "Case WHEN convert(nvarchar(100),b.new_account ) IS NULL THEN 'NO_DATA' ELSE convert(nvarchar(100),"
+ "b.new_account ) END AS AccountID,"
+ "Case WHEN c.Name IS NULL THEN 'NO_DATA' ELSE c.Name END as Name,"
+ "Case WHEN convert(nvarchar(100),a.OwnerId) IS NULL THEN 'NO_DATA' ELSE convert(nvarchar(100),"
+ "a.OwnerId) END as OwnerId, b.new_EOL,"
+ "Case WHEN a.JobTitle IS NULL THEN 'NO_DATA' ELSE a.JobTitle END as JobTitle,"
+ "Case WHEN a.FirstName IS NULL THEN 'NO_DATA' ELSE a.FirstName END as FirstName,"
+ "Case WHEN a.LastName IS NULL THEN 'NO_DATA' ELSE a.LastName END as LastName,"
+ "Case WHEN a.EMailAddress1 IS NULL THEN 'NO_DATA' ELSE a.EMailAddress1 END as EMailAddress1,"
+ "a.new_Support_RenewalContact,d.YomiFullName,d.InternalEMailAddress,"
+ "(select InternalEMailAddress from dbo.SystemUserBase where SystemUserId = e.new_VPId ) new_VPId,"
+ "(select InternalEMailAddress from dbo.SystemUserBase where SystemUserId = e.new_RVPId ) new_RVPId,"
+ "b.new_RenewalOpptyIDyr2,b.new_RenewalOpptyIDyr3,b.new_RenewalOpptyIDyr4,b.new_RenewalOpptyIDyr5,"
+ "Case when b.new_LevelofSupport = 100000000 then 'Platinum' "
+ "when b.new_LevelofSupport = 100000001 then 'Standard'"
+ "when b.new_LevelofSupport = 100000002 then 'NONE'"
+ "when b.new_LevelofSupport = 100000003 then 'Standard with AR'"
+ "end as LevelOFSupport"
+ " FROM"
+ " dbo.new_assetExtensionBase as b left outer join dbo.contact as a on a.AccountID=b.new_account"
+ " left outer join dbo.AccountBase as c on b.new_account=c.AccountId"
+ " left outer join dbo.SystemUserBase as d on c.OwnerId=d.SystemUserId"
+ " left outer join dbo.SystemUserExtensionBase as e on d.SystemUserId=e.SystemUserId "
+ "WHERE "
+ "(b.new_EOL >= ?) and "
+ "(b.new_EOL <= ? ) or "
+ "(b.new_EOL >= ?) and "
+ "(b.new_EOL <= ?) or "
+ "(b.new_EOL >= ?) and "
+ "(b.new_EOL <= ?) "
+ " order by Case WHEN convert(nvarchar(100),b.new_account ) IS NULL THEN 'NO_DATA' ELSE convert(nvarchar(100),b.new_account ) END,"
+ " a.new_Support_RenewalContact desc,b.new_RenewalOpptyIDyr2 desc,b.new_RenewalOpptyIDyr3 desc,b.new_RenewalOpptyIDyr4 desc,"
+ "b.new_RenewalOpptyIDyr5 desc");
答案 0 :(得分:0)
你的问题难以理解。你应该编辑它。
我可以帮助一方面:如何获得一年中的季度。
首先:不要使用java.util.Date&amp;日历类。众所周知,它们很麻烦。而是使用Joda-Time或与Java 8捆绑在一起的新java.time。*包。
如果您对宿舍的定义是一年中的第一天,然后每3个月,从每月1日开始,那么您在示例代码中的工作方式太难了。您知道,无论年份如何,月份数字将始终相同:
您可以在构建日期时间值时使用该月份编号。或者,您可以构建一年中第一天的日期时间,然后重复添加3个月。
Joda-Time DateTime与java.util.Date一样,代表日期和时间。因此,您需要将时间设置为您宿舍的一天中的第一时刻。如有疑问,请调用DateTime实例的withTimeAtStartOfDay
方法。
您应指定时区,因为一天的开始时间取决于特定时区。如果未指定时区,则使用JVM的默认时区。
DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" );
DateTime q1_2014 = new DateTime( 2014, 1, 1, 0, 0, 0, timeZone );
DateTime q2_2014 = q1_2014.plusMonths( 3 );
DateTime q3_2014 = q1_2014.plusMonths( 6 );
DateTime q4_2014 = q1_2014.plusMonths( 9 );