如何将存储过程的结果插入临时表?

时间:2016-07-05 13:32:14

标签: sql sql-server stored-procedures

如何在另一个过程中调用存储过程并将结果插入临时表?

注1:我不知道第一个程序的字段。

注2:有人早些时候已经提出过这个问题,但是没有得到正确回答。我无法在执行程序之前创建临时表,因为我不知道它返回的是什么。

1 个答案:

答案 0 :(得分:-2)

首先需要使用与过程返回的具有相同数据类型的列的确切数量和顺序来定义表变量,然后使用 private void startSchedule() { for(int i=0;i<temPojoData.size();i++) { tempPojo tem =temPojoData.get(i); /////////////////////// Daily and AllDays functionality start here ////////////////// if(tem.getDaysweekmonth().equals("Daily") ) { if(tem.getDaysbases().equals("AllDays")) { if (findDateBTwoDates(tem.getStartDate(), tem.getEndDate())) { Log.i("Daily Date", "Today Available"); layoutID += tem.getLayout(); } }else if(tem.getDaysbases().equals("Whole Day")){ }else if(tem.getDaysbases().equals("Morning")) { scheduleStartTimes.add(tem.getStartTime()); }else if(tem.getDaysbases().equals("After Noon")) { scheduleStartTimes.add(tem.getStartTime()); }else if(tem.getDaysbases().equals("Evening")) { scheduleStartTimes.add(tem.getStartTime()); }else if(tem.getDaysbases().equals("Night")) { scheduleStartTimes.add(tem.getStartTime()); }else if(tem.getDaysbases().equals("Choose Time")) { scheduleStartTimes.add(tem.getStartTime()); } } /////////////////////// Weekly and AllDays functionality start here ////////////////// else if(tem.getDaysweekmonth().equals("weekly") && tem.getDaysbases().equals("AllDays")) { if(tem.getDaysbases().equals("AllDays")) { } } /////////////////////// Monthly and AllDays functionality start here ////////////////// else if(tem.getDaysweekmonth().equals("montly") && tem.getDaysbases().equals("AllDays")) { if(tem.getDaysbases().equals("AllDays")) { } } } } private void findTimeBTwoTimes(String sTime,String eTime) { try { String string1 = "20:11:13"; Date time1 = new SimpleDateFormat("HH:mm:ss").parse(string1); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(time1); String string2 = "14:49:00"; Date time2 = new SimpleDateFormat("HH:mm:ss").parse(string2); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(time2); calendar2.add(Calendar.DATE, 1); String someRandomTime = "01:00:00"; Date d = new SimpleDateFormat("HH:mm:ss").parse(someRandomTime); Calendar calendar3 = Calendar.getInstance(); calendar3.setTime(d); calendar3.add(Calendar.DATE, 1); Date x = calendar3.getTime(); if (x.after(calendar1.getTime()) && x.before(calendar2.getTime())) { //checkes whether the current time is between 14:49:00 and 20:11:13. System.out.println(true); } } catch (ParseException e) { e.printStackTrace(); } } private boolean findDateBTwoDates(String sDate,String eDate) { try { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); String s = sDate.replace(" AM",""); String e = eDate.replace(" AM",""); String oeStartDateStr =sDate.replace("PM",""); String oeEndDateStr =eDate.replace("PM",""); Log.i("Start End Date ",sDate+"------------"+eDate); Calendar cal = Calendar.getInstance(); Integer year = cal.get(Calendar.YEAR); Date startDate = sdf.parse(oeStartDateStr); Date endDate = sdf.parse(oeEndDateStr); Date d = new Date(); String currDt = sdf.format(d); if ((d.after(startDate) && (d.before(endDate))) || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) { System.out.println("Date is between 1st april to 14th nov..."); return true; } /*else { System.out.println("Date is not between 1st april to 14th nov..."); }*/ }catch (Exception e){} return false; } 语句定义EXEC,如以下示例所示:

INSERT