Help with SELECT to get a total from a database field? ASP/VBScript
I have two tables, Events and Orders. The Events table:
eventID
title
ticketsavailable
The Orders table:
orderID
customerID
eventID
numberofticketspurchased
I want to be able to calculate the total number of tickets
purchased by all
customers.
I'd managed to vind out the total number of orders, for any
one event, by
doing the following:
(SELECT COUNT(*) FROM dbo.orders WHERE dbo.events.eventID =
dbo.orders.eventID) AS numberoforders
...I wondered if there was something similar, to give me the
total number of
tickets purchased? Thanks.
Regards
Nathon
tradmusic.com wrote:
> "Dooza" <[email protected]> wrote in message
> news:[email protected]...
>> tradmusic.com wrote:
>>> "Dooza" <[email protected]> wrote in
message
>>> news:[email protected]...
>>>> tradmusic.com wrote:
>>>>> Also, this will only return events that
have sold tickets right?
>>>>> Ideally I'd like to show all events, but
I guess if they are linked by
>>>>> eventID, I'm kinda stuck?
>>>> What exactly do you want the output to look
like?
>>>>
>>>> Steve
>>> I wanted to view a list of all of the events,
with a column that showed
>>> the number of tickets left.
>>>
>>> In my events table, I have a "tickets available"
column, which is the
>>> original stock number. In my output, I basically
wanted to perform a
>>> calculation that would subtract the SUM column
value from the tickets
>>> available column, giving me the number of
tickets left in stock.
>>>
>>> Thanks again.
>>> Nathon.
>> Ok, so you want:
>>
>> 1. Event
>> 2. Tickets Sold (SUM)
>> 3. Tickets Available
>> 4. Tickets Remaining
>>
>> Grouped by Event.
>>
>> SELECT dbo.events.eventtitle,
SUM(dbo.webordersitems.ticketquantity)
>> AS ticketsSold, dbo.events.ticketsavailable,
>> (dbo.events.ticketsavailable -
(SUM(dbo.webordersitems.ticketquantity)))
>> AS ticketsRemaining
>> FROM dbo.events JOIN dbo.webordersitems ON
dbo.events.bookeventID =
>> dbo.webordersitems.bookeventID
>> GROUP BY dbo.events.eventtitle
>>
>> Steve
>
> Thanks Steve, that's really helpful.
> This is still only going to show events that have had a
sale though, right?
>
> I guess I could just create two recordsets on my page,
one for events that
> have had sales, and one for the remaining events.
> My understanding is that, because we are running a JOIN
by bookeventID, it
> wouldn't actually be possible to display all events
because, by the very
> nature of the statement, the bookeventID has to appear
in the webordersitems
> table, indicating that a sale had taken place.
>
> Much appreciated. Thanks again.
Hi Nathan, I think its the combination of the JOIN and the
GROUP BY
which is preventing you from getting exactly what you want.
If you look
up JOINS you will find one called an OUTER JOIN, that will
help, but due
to the GROUP BY it will fail, so I think for the moment your
best bet is
2 recordsets.
Steve
Similar Messages
-
i have an itouch, most songs i got off my cd's. i have a new laptop and want to put songs from itouch to laptop.I can only get the songs that i purchased onto the laptop? need help with how to get the rest of the songs (from my cd's) from itouch to laptop please??
See this previous discussion:
Recovering your iTunes library from your iPod or iOS device: Apple Support Communities -
Help with SELECT - selecting range of numbers
Hi,
I need a help with SELECT statement. I want to select Dates starting from today and ending 30 days back. So the result would be like:
TRUNC(SYSDATE)
TRUNC(SYSDATE) - 1
TRUNC(SYSDATE) - 2
TRUNC(SYSDATE) - 3
TRUNC(SYSDATE) - 30I was thinking to simply select truncated SYSDATE in first column, and in second column numbers 0, 1, 2, ... 30. Then I would simply do a difference first column - second column. But how to select such sequence of numbers? I don't want to select each number (date) in separate select statement and then unioning them.
Does anybody have an idea?
Thanks for help, DanSQL> select trunc(sysdate) - level + 1 as dt
2 from dual
3 connect by level <= 31
4 ;
DT
07/01/2013
06/01/2013
05/01/2013
04/01/2013
03/01/2013
02/01/2013
01/01/2013
31/12/2012
30/12/2012
29/12/2012
28/12/2012
27/12/2012
26/12/2012
25/12/2012
24/12/2012
23/12/2012
22/12/2012
21/12/2012
20/12/2012
19/12/2012
DT
18/12/2012
17/12/2012
16/12/2012
15/12/2012
14/12/2012
13/12/2012
12/12/2012
11/12/2012
10/12/2012
09/12/2012
08/12/2012
31 rows selected -
Getting specific values From a database in Java
Hey,
I'm using XE and building an application in Java to do basic CRUD operations on the database.
One of these operations is searching for a customer by last name (which runs fine) and the result of the query (a customer ID, a first name, and a last name) is displayed in a JTable. I want to be able to click on the record I need and use the customer ID to do an insert on another table CUSTOMER_PURCHASES which maps purchases to customers.
How do I go about doing this knowing that customer ID is an auto-incremented number (using a SEQUENCE)?
I thought about creating a variable in Java of type String called customerID and initialize it like this: String customerID = "CUSTOMER_SEQUENCE.nextval"
But by doing this, I suspect that I'll be getting the next available customerID, not the one from the record I selected.
Can anybody suggest a workaround or lead me in the right direction?
Thank you in advance for the help and sorry about the long post, but I'm a newvbie to this field.As per raychen's advice, I was able to get the image from the database and bring it over into JavaFX.
In my java class I retrieved the image as follows:
BufferedImage image = null; //Buffered image coming from database
InputStream fis = null; //Inputstream
try{
ResultSet databaseResults; //Returned results from DB
stmt = conn.createStatement(); //Create the SQL statement
databaseResults= stmt.executeQuery("SELECT * FROM mydb.`user` WHERE userID = 'username';"); //Execute query
fis = blah.getBinaryStream(3); //It happens that the 3rd column in my database is where the image is stored (a BLOB)
image = javax.imageio.ImageIO.read(fis); //create the BufferedImaged
} catch (Exception e){
//print error if caught
return image //My function returns a BufferedImage objectSo in JavaFX, depending on how you have it set up, you essentially get the returned BufferedImage and create the image as follows:
var bufferedImage : BufferedImage = theJavaFunctionThatReturnsABufferedImage();
var newImage : Image = javafx.ext.swing.SwingUtils.toFXImage(bufferedImage); //BufferedImageCheers and Happy New Year. -
How to get the value from a database without submitting a jsp page
I have a jsp which has a text box depending on the value entered I want to get the value from a database for other two fields with out submitting jsp page. I am using struts.
Thanks For any assistance provided.Alright,here is an example for you for the first case.
Present.jsp:
============
<html:html>
<head>
<title><html:message key="page.title"/></title>
</head>
<body>
<html:form action="ChangeEvent.do">
<html:hidden property="method"/>
<!-- Submitting the Form onKeyUp of EmpId field and trying to save the
state of the Form in the scope of session -->
Emp Id:<html:text property="empId" size="5" onkeyup="if(true){this.form.elements[0].value='populateDetails';this.form.submit();}"/>
Emp Name:<html:text property="empName" size="10" />
Email Address:<html:text property="email" size="10" />
<html:submit>Submit</html:submit>
</html:form>
</body>
</html:html>struts-config.xml:
==================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- Form bean which stores the properties of all the Form elements -->
<form-beans>
<form-bean name="employeeFormBean" type="org.apache.struts.action.DynaActionForm">
<form-property name="empId" type="java.lang.String"/>
<form-property name="empName" type="java.lang.String"/>
<form-property name="email" type="java.lang.String" />
</form-bean>
</form-bean>
<action-mappings>
<action path="/ChangeEvent" type="Test.GetChangeAction" name="employeeFormBean" scope="request" parameter="method">
<!-- On successful call of DB the Page has to be forwarded to the same page again by
uploading updated form bean values. -->
<forward name="success" path="/Present.jsp"></forward>
<forward name="failed" path="/error.jsp"></forward>
</action>
</action-mappings>
</struts-config>GetChangeAction.java:
=====================
public class GetChangeAction extends DispatchAction{
public ActionForward populateDetails(ActionMapping mapping,ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
DynaActionForm dForm = (DynaActionForm)form;
String empId = dForm.get("empId");
// calling Model / Db and then getting back Employee Details
EmployeeBean eb = ModelUtils.getDetails(empId);
// Updating form bean by updating values from the Model
dForm.set("empName".eb.getEmpName());
dForm.set("email".eb.getEmail());
return mapping.findForward("success");
}well to me this should work regardless to any browser but we need to make sure we put in our logic properly. -
How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.
If the data is on a remote server (for example, PHP running on a web server, talking to a MySQL server) then you do this in an AIR application the same way you would do it with any Flex application (or ajax application, if you're building your AIR app in HTML/JS).
That's a broad answer, but in fact there are lots of ways to communicate between Flex and PHP. The most common and best in most cases is to use AMFPHP (http://amfphp.org/) or the new ZEND AMF support in the Zend Framework.
This page is a good starting point for learning about Flex and PHP communication:
http://www.adobe.com/devnet/flex/flex_php.html
Also, in Flash Builder 4 they've added a lot of remote-data-connection functionality, including a lot that's designed for PHP. Take a look at the Flash Builder 4 public beta for more on that: http://labs.adobe.com/technologies/flashbuilder4/ -
Help with selecting chuncks of data from a table
Hi all,
I need help with a query that should do the following.
I have a table with vessel messages, and I need to get the last "NumMsgs" messages from a group of vessels.
The problem I have is that if I order the table by Vessel_ID, MessageDate DESC, I can´t do ROWNUM < NumMsgs (<-- Then number of messages to be shown is a user parameter)
I know it should be something like:
select * from (
select *
from Messages m
where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
order by m.V_ID, m.MESSAGEDATE desc
where rownum < :NumMsgs
Any ideas?
Thanks in advance !Hi,
What about :
select *
from (
select m.*, row_number() (order by m.V_ID, m.MESSAGEDATE desc) rn
from Messages m
where TRIM(m.V_ID) = '11597' /* I was trying for a single vessel atm */
where rn < :NumMsgsAnyway, I don't very well understand your problem, your query work fine, see for example :
SQL> ed
Wrote file afiedt.buf
1 select object_name, object_id
2 from
3 (select object_name, object_id, row_number() over (order by object_id desc) as rn
4 from dba_objects)
5* where rn < 4
SQL> /
PS_TL_MTCHD_118 71763
PS_TL_MTCHD_117 71762
PS_TL_MTCHD_116 71761
SQL> ed
Wrote file afiedt.buf
1 select object_name, object_id
2 from
3 (select object_name, object_id
4 from dba_objects
5 order by object_id desc)
6* where rownum < 4
SQL> /
PS_TL_MTCHD_118 71763
PS_TL_MTCHD_117 71762
PS_TL_MTCHD_116 71761
SQL> Nicolas.
Message was edited by:
N. Gasparotto -
Help with select from USREXTID table
HI,
I try to select from table USREXTID and when i try to use do the select like below
SELECT bname FROM usrextid
INTO TABLE lt_bname
WHERE type = 'DN'
AND extid = temp_extid
AND status = 'X'.
here when i take the exact entry from the table i get sy-subrc = 0.
Working o.k.
when i try to use the select for SAML like
SELECT bname FROM usrextid
INTO TABLE lt_bname
WHERE type = 'SA'
AND extid = temp_extid
AND status = 'X'.
I get sy-subrc = 4.
I have entry on the table with SA and i copy all the entry from EXTID field and put it on
temp_extid ,
What can be the problem ?
Best Regards
Nina
Edited by: Nina C on Jun 15, 2009 10:05 AMHI,
i copy the entry from the table exactly and i put it ,
The problem here is with SA.
when i copy entry from table with DN it work fine.
it's behave strange .
Best Regards
Nina -
Help with selecting complete words in text field. Add Icons to Text Field
Hi,
I am creating GUI for a Email program. The user can send emails, send files as attachment.
When the user selects his files to attach I am displaying them as a string in a TextField along with there size
The user can attach files with the help of FileChooser dialog invoked on click of a JButton
e.g. file1.txt(5K), file2.txt(10K)
Now whenever user wants to delete one of the files I want him to delete the entire file name with its size.
So that I get the correct string of file names to send to the smtp server.
Any one got clues how I can restrict the user to delete the complete name of the file.
I think if I could make the user to select entire names, and restrict him from moving in the textfield character by character it would be possible. But not sure how to exactly achieve that
Also I would like to display the Icon along with the file names in the TextField any ideas how it can be done.
I get the Icon from the File dialog but don't know how to show it up in the TextFieldThe safest way to handle this is using a JList. But it is possible to do this with the JTextArea. For selecting the entire file, put an action listener on the JTextArea. If someone clicks ona word, it will highlight, by using setSelectionStart(int) and setSelectionEnd(int) found in JTextComponent. Use 0, the length, and the index of the commas for the points to start and end selection. As far as the images, I know it can be done (smileys in chat messages for example) but I've never seen the code to do it. It may just override the paint method and paint in an ImageIcon at the specified location.
-
Please help..How to get the values from a for loop in Action class
I have alist of students say A(name, class, subjects, teacher).
I need to display all the items in the list A into JSP,
and then also the details of (name, class, subjects, teacher).
in the action class,
After getting the list of students from the database with ORM Layer(Toplink),
I set request.setAttribute("students",listOfStudents).
And then Iterate over the list and pass the parameter as student ID to the functions
getClass(), getSubject(), getTeacher().
Collection listOfStudents=getStudents();
request.setAttribute("students",listOfStudent);
for (Iterator itr = lisOfStudents.iterator(); itr.hasNext();)
Collection classOfStudent=getClass(studentID);
request.setAttribute("class",classOfStudent);
Collection subjectOfStudent=getSubject(studentID);
request.setAttribute("subject",subjectOfStudent);
Collection teacherOfStudent=getTeacher(studentID);
request.setAttribute("teacher",teacherOfStudent);
mapping.findForward("listOfStudentDetails);
In JSP
<c:forEach var="stud" items="${students}">
//display name in Name Column
//one student may have more than one subject
<c:forEach var="sub" items="${subject}">
.......//display the subjects of the student
//and repeat the same for the other details
</c:forEach>
The problem I am facing is
If the last student has no subjects, no teachers
It is displaying null for all the other students.
I am understanding that the values are getting overwitten in the loop and the is frwede to JSP with the recentmost values for the attributes.
What could be a possible solution so that I retrieve the values for individual students and will be able to display on JSP?
((Please ignore any syntax in theabove example it is just a mock up created from the real problem)The issue here is while you are retrieving all the details, you are consistently overwriting them in the request.setAttribute() call before you get to the JSP to display them.
Do you actually have a class/object called Student?
That object should have attributes for classes, subjects, teachers (all of which are lists apparently)
public class Student{
String name;
List classes;
List subjects;
List teachers;
// appropriate getter/setter methods
}Then you load each student, and populate its individual lists.
That lets you pass the list of students, each student having its own lists for display.
Hope this helps,
evnafets -
How ias integrate with Snacktory for getting main text from an html page
Hi All,
i am new to endeca and ias, i have an requirement, need to get main text from whole html page before ias save text to Endeca_Document_Text property,
as ias save all text in page to endeca_document_text property, it is not ok for reading when show in web page, i use an third party API to filter out the main text from original page,
now i want to save these text to endeca_document_text property,
an another question,
i get zero page when doing the logic of filtering main text from original html text in ParseFilter( HTMLMetatagFilter implements ParseFilter) using Snacktory.
if only do little things, it will work fine, if do more thing, clawer fail to crawl page. any one know how to fix it.
log for clawler.
Successfully set recordstore configuration.
INFO 2013-09-03 00:56:42,743 0 com.endeca.eidi.web.Main [main] Reading seed URLs from: /home/oracle/oracle/endeca/IAS/3.0.0/sample/myfirstcrawl/conf/endeca.lst
INFO 2013-09-03 00:56:42,744 1 com.endeca.eidi.web.Main [main] Seed URLs: [http://www.liferay.com/community/forums/-/message_boards/category/]
INFO 2013-09-03 00:56:43,497 754 com.endeca.eidi.web.db.CrawlDbFactory [main] Initialized crawldb: com.endeca.eidi.web.db.BufferedDerbyCrawlDb
INFO 2013-09-03 00:56:43,498 755 com.endeca.eidi.web.Crawler [main] Using executor settings: numThreads = 100, maxThreadsPerHost=1
INFO 2013-09-03 00:56:44,163 1420 com.endeca.eidi.web.Crawler [main] Fetching seed URLs.
INFO 2013-09-03 00:56:46,519 3776 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] come into EndecaHtmlParser getParse
INFO 2013-09-03 00:56:46,519 3776 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] come into HTMLMetatagFilter
INFO 2013-09-03 00:56:46,519 3776 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] meta tag viewport ==minimum-scale=1.0, width=device-width
INFO 2013-09-03 00:56:52,889 10146 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] come into EndecaHtmlParser getParse
INFO 2013-09-03 00:56:52,889 10146 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] come into HTMLMetatagFilter
INFO 2013-09-03 00:56:52,890 10147 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-1] meta tag viewport ==minimum-scale=1.0, width=device-width
INFO 2013-09-03 00:56:59,184 16441 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] come into EndecaHtmlParser getParse
INFO 2013-09-03 00:56:59,185 16442 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] come into HTMLMetatagFilter
INFO 2013-09-03 00:56:59,185 16442 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] meta tag viewport ==minimum-scale=1.0, width=device-width
INFO 2013-09-03 00:57:07,057 24314 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] come into EndecaHtmlParser getParse
INFO 2013-09-03 00:57:07,057 24314 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] come into HTMLMetatagFilter
INFO 2013-09-03 00:57:07,057 24314 com.endeca.eidi.web.parse.HTMLMetatagFilter [pool-1-thread-2] meta tag viewport ==minimum-scale=1.0, width=device-width
INFO 2013-09-03 00:57:07,058 24315 com.endeca.eidi.web.Crawler [main] Seeds complete.
INFO 2013-09-03 00:57:07,090 24347 com.endeca.eidi.web.Crawler [main] Starting crawler shut down
INFO 2013-09-03 00:57:07,095 24352 com.endeca.eidi.web.Crawler [main] Waiting for running threads to complete
INFO 2013-09-03 00:57:07,095 24352 com.endeca.eidi.web.Crawler [main] Progress: Level: Cumulative crawl summary (level)
INFO 2013-09-03 00:57:07,095 24352 com.endeca.eidi.web.Crawler [main] host-summary: www.liferay.com to depth 1
host depth completed total blocks
www.liferay.com 0 0 1 1
www.liferay.com 1 0 0 0
www.liferay.com all 0 1 1
INFO 2013-09-03 00:57:07,096 24353 com.endeca.eidi.web.Crawler [main] host-summary: total crawled: 0 completed. 1 total.
INFO 2013-09-03 00:57:07,096 24353 com.endeca.eidi.web.Crawler [main] Shutting down CrawlDb
INFO 2013-09-03 00:57:07,160 24417 com.endeca.eidi.web.Crawler [main] Progress: Host: Cumulative crawl summary (host)
INFO 2013-09-03 00:57:07,162 24419 com.endeca.eidi.web.Crawler [main] Host: www.liferay.com: 0 fetched. 0.0 mB. 0 records. 0 redirected. 4 retried. 0 gone. 0 filtered.
INFO 2013-09-03 00:57:07,162 24419 com.endeca.eidi.web.Crawler [main] Progress: Perf: All (cumulative) 23.6s. 0.0 Pages/s. 0.0 kB/s. 0 fetched. 0.0 mB. 0 records. 0 redirected. 4 retried. 0 gone. 0 filtered.
INFO 2013-09-03 00:57:07,162 24419 com.endeca.eidi.web.Crawler [main] Crawl complete.
~/oracle/endeca
-======================================
source code for parsefilter
package com.endeca.eidi.web.parse;
import java.util.Map;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.log4j.Logger;
import org.apache.nutch.metadata.Metadata;
import org.apache.nutch.parse.HTMLMetaTags;
import org.apache.nutch.parse.Parse;
import org.apache.nutch.parse.ParseData;
import org.apache.nutch.parse.ParseFilter;
import org.apache.nutch.protocol.Content;
import de.jetwick.snacktory.ArticleTextExtractor;
import de.jetwick.snacktory.JResult;
public class HTMLMetatagFilter implements ParseFilter {
public static String METATAG_PROPERTY_NAME_PREFIX = "Endeca.Document.HTML.MetaTag.";
public static String CONTENT_TYPE = "text/html";
private static final Logger logger = Logger.getLogger(HTMLMetatagFilter.class);
public Parse filter(Content content, Parse parse) throws Exception {
logger.info("come into EndecaHtmlParser getParse");
logger.info("come into HTMLMetatagFilter");
//update the content with the main text in html page
//content.setContent(HtmlExtractor.extractMainContent(content));
parse.getData().getParseMeta().add("FILTER-HTMLMETATAG", "ACTIVE");
ParseData parseData = parse.getData();
if (parseData == null) return parse;
extractText(content, parse);
logger.info("update the content with the main text content");
return parse;
private void extractText(Content content, Parse parse){
try {
ParseData parseData = parse.getData();
if (parseData == null) return;
Metadata md = parseData.getParseMeta();
ArticleTextExtractor extractor = new ArticleTextExtractor();
String sourceHtml = new String(content.getContent());
JResult res = extractor.extractContent(sourceHtml);
String text = res.getText();
md.set("Endeca_Document_Text", text);
} catch (Exception e) {
// TODO: handle exception
public static void log(String msg){
System.out.println(msg);
public Configuration getConf() {
return null;
public void setConf(Configuration conf) {but it only extracts URLs from <A> (anchor) tags. I want to be able to extract URLs from <MAP> tags as wellGee, do you think you could modify the code to check for "Map" attributes as well.
Can someone maybe point a page containing info on the HTML toolkit for me?It's called the API. Since you are using the HTMLEditorKit and an ElementIterator and an AttributeSet, I would start there.
There is no such API that says "get me all the links", so you have to do a little work on your own.
Maybe you could use a ParserCallback and every time you get a new tag you check for the "href" attribute. -
Need help with select that month range with flexible first date
Hello everyone,
I am trying to create a selection of month range (will be in a WITH clause) for a report to display monthly data. But the first month start date can be any date. (Not necessarily the first date of the month)
Examples:
Report input parameters:
Start Date: 08/10/12
End Month: Dec 2012
I was trying to build a with select that will list
Month_Start, Month_End
08/10/12, 31/10/12
01/11/12, 30/11/12
01/12/12, 31/12/12
OR
Month_Start, Next_Month
08/10/12, 01/11/12
01/11/12, 01/12/12
01/12/12, 01/01/13
End month is optional, so if no value the select will list only
08/10/12, 01/11/12
Oracle Database Details is
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
My code so far is
VARIABLE P50_START_DATE VARCHAR2 (10)
VARIABLE P50_END_MONTH VARCHAR2 (10)
EXEC :P50_START_DATE := '10/10/2012';
EXEC :P50_END_MONTH := '31/12/2012';
SELECT to_char(:P50_START_DATE) AS start_date
, ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), 1) AS next_month
FROM dual
union
SELECT to_char(ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM-1)) AS start_date
, ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM) AS next_month
--, rownum
from all_objects
where
rownum <= months_between(to_date(NVL(:P50_END_MONTH, :P50_START_DATE),'DD/MM/YYYY'), add_months(to_date(:P50_START_DATE,'DD/MM/YYYY'), -1))
and rownum > 1If I put comment – on line and rownum > 1, as
-- and rownum > 1The result I get is
START_DATE NEXT_MONTH
01/10/12 01/10/12
01/11/12 01/11/12
01/12/12 01/01/13
10/10/2012 01/11/12 But when I try to remove the duplicate period (of the first month) out by restrict rownum, it do not return any rows for the second select at all. The result I get is:
START_DATE NEXT_MONTH
10/10/2012 01/11/12 Can anyone advise what wrong with the select statement ?
Thanks a lot in advance,
AnnHi,
Here's one way:
WITH params AS
SELECT TO_DATE (:p50_start_date, 'DD/MM/YYYY') AS start_date
, TO_DATE (:p50_end_month, 'DD/MM/YYYY') AS end_date
FROM dual
SELECT GREATEST ( start_date
, ADD_MONTHS ( TRUNC (start_date, 'MONTH')
, LEVEL - 1
) AS month_start
, LEAST ( end_date
, ADD_MONTHS ( TRUNC (start_date, 'MONTH')
, LEVEL
) - 1
) AS month_end
FROM params
CONNECT BY LEVEL <= 1 + MONTHS_BETWEEN ( end_date
, TRUNC (start_date, 'MONTH')
;:p50_end_month doesn't have to be the last day of the month; any day will work.
If you want to generate a Counter Table containing the integers 1 througn x in SQL, you could say
SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= x
;but, starting in Oracle 9.1, it's much faster to say
SELECT LEVEL AS n
FROM dual -- or any table containing exactly 1 row
CONNECT BY LEVEL <= x
;Also, x can be greater than the number of rows in all_objects. -
Hello,
My table looks similar to this, I have removed a few columns:
table1:
Forecast_id Forecast_name Freeze Enabled
100 Q12009 N Y
101 Q22009 N Y
table2:
forecast_id parameter_name parameter_value
100 StartDate 01/01/2009
100 EndDate 03/31/2009
100 Growth % 20
100 Retailer Walmart
101 StartDate 04/01/2009
101 EndDate 06/30/2009
101 Growth % 20
101 Retailer Walmart
What i need to do is
select from table 1, forecast name & freeze
where in table2 parameter = Retailer, Parameter value = Walmart and
Start Date = 01/01/2009 and End Date = 03/31/2009
here is my query is there a easy way this can be done. I have used decode function in the past for similar situation for counting and grouping.
SELECT i.FORECAST_ID,
i.FORECAST_NAME,
i.FREEZE_FLAG
FROM (
SELECT x.FORECAST_ID,
x.FORECAST_NAME,
x.FREEZE_FLAG
FROM (
SELECT A.FORECAST_ID,
A.FORECAST_NAME,
A.FREEZE_FLAG
FROM GC_FORECAST A, GC_FORECAST_PARAMETERS B
WHERE A.FORECAST_ID = B.FORECAST_ID
AND B.PARAMETER_NAME = 'Retailer'
AND B.PARAMETER_VALUE = 'Walmart'
) x, GC_FORECAST_PARAMETERS y
WHERE x.FORECAST_ID = y.FORECAST_ID
AND y.PARAMETER_NAME = 'StartDate'
AND y.PARAMETER_VALUE = '01/01/2009'
) i, GC_FORECAST_PARAMETERS j
WHERE i.FORECAST_ID = j.FORECAST_ID
AND j.PARAMETER_NAME = 'EndDate'
AND j.PARAMETER_VALUE = '03/31/2009';
Thank you for your time and help.
Vidhya
Edited by: snaraya9 on Dec 5, 2008 12:03 PM
Edited by: snaraya9 on Dec 5, 2008 12:06 PMSolution
SELECT gc_forecast.forecast_id, gc_forecast.forecast_name, gc_forecast.freeze,
gc_forecast.enabled
FROM gc_forecast,
(SELECT forecast_id,
MAX (CASE
WHEN parameter_name = 'StartDate'
AND parameter_value = '01/01/2009'
THEN 1
ELSE 0
END
) cond1,
MAX (CASE
WHEN parameter_name = 'EndDate'
AND parameter_value = '03/31/2009'
THEN 1
ELSE 0
END
) cond2,
MAX (CASE
WHEN parameter_name = 'Retailer'
AND parameter_value = 'Walmart'
THEN 1
ELSE 0
END
) cond3
FROM gc_forecast_parameters
GROUP BY forecast_id) gf
WHERE gc_forecast.forecast_id = gf.forecast_id
AND gf.cond1 = 1
AND gf.cond2 = 1
AND gf.cond3 = 1
Demo
SQL*Plus: Release 10.1.0.4.2 - Production on Ven. Déc. 5 15:34:14 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connecté à :
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> /* Formatted on 2008/12/05 15:33 (Formatter Plus v4.8.8) */
SQL> WITH gc_forecast_parameters AS
2 (SELECT 100 forecast_id, 'StartDate' parameter_name,
3 '01/01/2009' parameter_value
4 FROM DUAL
5 UNION ALL
6 SELECT 100, 'EndDate', '03/31/2009'
7 FROM DUAL
8 UNION ALL
9 SELECT 100, 'Growth', '% 20'
10 FROM DUAL
11 UNION ALL
12 SELECT 100, 'Retailer', 'Walmart'
13 FROM DUAL
14 UNION ALL
15 SELECT 101, 'StartDate', '04/01/2009'
16 FROM DUAL
17 UNION ALL
18 SELECT 101, 'EndDate', '06/30/2009'
19 FROM DUAL
20 UNION ALL
21 SELECT 101, 'Growth', '% 20'
22 FROM DUAL
23 UNION ALL
24 SELECT 101, 'Retailer', 'Walmart'
25 FROM DUAL),
26 gc_forecast AS
27 (SELECT 100 forecast_id, 'Q12009' forecast_name, 'N' freeze, 'Y' enabled
28 FROM DUAL
29 UNION ALL
30 SELECT 101, 'Q22009', 'N', 'Y'
31 FROM DUAL)
32 SELECT gc_forecast.forecast_id, gc_forecast.forecast_name, gc_forecast.freeze,
33 gc_forecast.enabled
34 FROM gc_forecast,
35 (SELECT forecast_id,
36 MAX (CASE
37 WHEN parameter_name = 'StartDate'
38 AND parameter_value = '01/01/2009'
39 THEN 1
40 ELSE 0
41 END
42 ) cond1,
43 MAX (CASE
44 WHEN parameter_name = 'EndDate'
45 AND parameter_value = '03/31/2009'
46 THEN 1
47 ELSE 0
48 END
49 ) cond2,
50 MAX (CASE
51 WHEN parameter_name = 'Retailer'
52 AND parameter_value = 'Walmart'
53 THEN 1
54 ELSE 0
55 END
56 ) cond3
57 FROM gc_forecast_parameters
58 GROUP BY forecast_id) gf
59 WHERE gc_forecast.forecast_id = gf.forecast_id
60 AND gf.cond1 = 1
61 AND gf.cond2 = 1
62 AND gf.cond3 = 1;
FORECAST_ID FORECA F E
100 Q12009 N Y
SQL> -
Hi Team
WE have a EBS 11.5.10.2 with DB 11.1.0,7 on HPUX 11.23.
And we have a error;
APP:
FRM-40735: ON_ERROR trigger raised unhandled exception ORA-01001
SQL> select fnd_web_sec.URLEncrypt('hello', 'world') from dual;
select fnd_web_sec.URLEncrypt('hello', 'world') from dual
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 10119
Session ID: 978 Serial number: 7
Regards,
GuidoModeration:
Stay with your original thread on this topic:
https://forums.oracle.com/thread/2595095
It is current and people have already tried to help you there.
This new duplicate post is locked. -
Help with loading pictures in my organizer from elements 9 trial version
I downloaded Trial Version of elements 9 last thursday. Since then I am trying to get someone at Adobe to tell me why, when I open Organizer there are NO pictures from my Pictures Albums. No help from them because they do NOT service "trail versions" WOW. cannot believe that. Someone please help. I do get an error message when I open through the "download" page. it says "cannot open because my file is the wrong type? do not understand. I previously had elements 7 on board but uninstalled it after I lost 1000 pictures and spent 3 months trying to get info as to "where are they" no one could help. So, did I do something wrong or is existing elements hiding in my hard drive stopping me from installing 9 Help need more info ie: specific file path etc. I will provide. Thank you
Hanna,
Some considerations with the trial of CS5: obviously, only 30 days of usage, nothing MPEG-2 is supported, and many other flavors of MPEG are also not supported. This means that you will NOT be able to ingest anything MPEG-2, likely nothing AVCHD, or similar, and you will NOT be able to use Encore for any DVD/BD authoring in the trial. Though there is no watermark, the CS5 trial is very, very limited, and one can really only edit DV-AVI, and Export to DV-AVI, or very similar.
Neale's suggestion is the best solution, IMHO. There are also freeware editors, like Womble, that might work for you, but there is a learning curve, due to the GUI.
Good luck,
Hunt
Maybe you are looking for
-
Hi everyone ☺ I’m finally planning to start recording what I play, and after some hours of wandering on the web I found some interesting possibilities. Now what I need is to decide which one is more suitable for my needs, and here comes the moment fo
-
I have no idea if this is a problem with my iMac or with my iPod. I have an iMac G5 (no cam) and an iPod w/click wheel (40GB). Two weeks ago I connected my iPod to my Mac for the first time in a while in order to update it. I received an error from i
-
Runtime Error displaying Linked List
Hi, I've got a main class with a linked list which I am trying to display but I seem to be getting a "Class Cast Exception" eventhough I type cast the list as a String. Can anyone help please. The code is below: import java.util.*; public class Libra
-
How to integration obiee Authentication with external app?
now i need integrate obiee with external app(web application). one user have 2 roles. one is teacher, others is school admin. when he login in external app, the first screen show teacher and school amdin. he click teacher login in this system. after
-
what is the use of DATA LINK MODE check box in ibrowser ? What r the methods in ibrowser?