EJB Query Problem
Hi All,
I`m using jdeveloper 11g and I have an EJB query select distinct substr(o.hostName, 1,10) from Host o where o.hostName like :searchPrefix
When i run this query I get this error message
javax.persistence.PersistenceException: Exception [EclipseLink-8024] (Eclipse Persistence Services - 1.2.0.v20091016-r5565): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [Host.distinctVlid: select distinct substr(o.hostName, 1,10) from Host o where o.hostName like :searchPrefix], line 1, column 22: syntax error at [(].
Internal Exception: MismatchedTokenException(81!=32)
Is it forbidden to use substr or distinct in ejb querys?
Hi Pedja,
I have tried to use your suggestion and created this method
public List<String> getHostVlidSuggestion(Object searchPrefix) {
Query query = em.createQuery("select distinct substring(o.hostName, 1, 10) as hostName from Host o where o.hostName like :searchPrefix");
query.setParameter("searchPrefix", searchPrefix);
query.setMaxResults(10);
return query.getResultList();
Now I`m getting this error
Exception [EclipseLink-6088] (Eclipse Persistence Services - 1.2.0.v20091016-r5565): org.eclipse.persistence.exceptions.QueryException
Exception Description: There are no attributes for the ReportQuery.
at org.eclipse.persistence.exceptions.QueryException.noAttributesForReportQuery(QueryException.java:815)
at org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1032)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:464)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:732)
at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1572)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:207)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:141)
at org.eclipse.persistence.in
Got any idea?
Edited by: Azzaiel on Jun 2, 2010 6:43 PM
Similar Messages
-
Hello APEX people,
I posted my problem here:
Designing LOV Query Problem
What I have is a sequence like this:
CREATE SEQUENCE
DR_SEQ_FIRST_SCHEDULE_GROUP
MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
CACHE 6 ORDER CYCLE ;
What I need would be a SQL query returning all possible values oft my sequence like:
1
2
3
4
5
6
7
I want to use it as a source for a LOV...
The reason why I use the cycling sequence is: My app uses it to cycle scheduling priorities every month to groups identified by this number (1-7).
In the Admin Form, I want to restrict the assignment in a user friendly way - a LOV.
Thanks
JohannHere ist the solution (posted by michales in the PL/SQL forum):
SQL> CREATE SEQUENCE
dr_seq_first_schedule_group
MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
CACHE 6 ORDER CYCLE
Sequence created.
SQL> SELECT LEVEL sn
FROM DUAL
CONNECT BY LEVEL <= (SELECT max_value
FROM user_sequences
WHERE sequence_name = 'DR_SEQ_FIRST_SCHEDULE_GROUP')
SN
1
2
3
4
5
6
7
7 rows selected. -
EJB query language help!!
Hi all, I have been trying to run a ejb query on JBoss 4.0.5, using built in hypersonic db, For some strange reasons am able to fetch all objects from db without any where clause but if am using a where clause with an attribute name from the entitybean am unable to retrieve any results.
I get an org.hibernate.QueryException, could not resolve property : "property name"
My ejb query looks like this...
SELECT template FROM TemplateSelect template WHERE template.template_name='Template_One'
TemplateSelect is my entity bean class and I do have an attribute named template_name in my bean class.
could any one please suggest me what could be wrong and also direct me to a good tutorial on ejb query language as well as I am fairly new to hibernate and ejb3 !
tons of thanks in advance!
pravinHi Anuradha ,
I'm afraid the query language does not support retrieving the date portion (i.e. truncating the time) from a date field.
I propose you turn you named into a BETWEEN query taking two parameters one for the beginning of the day and another for the end of the day. Then your named query could look like:
SELECT max(o.req_id) FROM requests o WHERE o.requestdate BETWEEN :start AND :end
The following code creates two calendar instances for the current day, one for 00:00:00 and another for 23:59:59:
Calendar start = Calendar.getInstance();
start.set(Calendar.HOUR_OF_DAY, 0);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = Calendar.getInstance();
end.set(Calendar.HOUR_OF_DAY, 23);
end.set(Calendar.MINUTE, 59);
end.set(Calendar.SECOND, 59);
end.set(Calendar.MILLISECOND, 999);
Here is some sample code that creates a query instance for a named query called findMaxRequestPerDay and passes the Date of the above Calendar instance as actual parameter values. It assumes the named query is called findMaxRequestPerDay and the req_id field is a long:
Query query = em.createNamedQuery("findMaxRequestPerDay");
query.setParameter("start", start.getTime());
query.setParameter("end", end.getTime());
Long max = (Long)query.getSingleResult();
I hope this helps.
Regards Michael -
SQL+-MULTI TABLE QUERY PROBLEM
HAI ALL,
ANY SUGGESTION PLEASE?
SUB: SQL+-MULTI TABLE QUERY PROBLEM
SQL+ QUERY GIVEN:
SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
DLC_POLYMORPHS_NORMAL_VALUE FROM PATIENTS_MASTER1, HAEMATOLOGY1,
DIFFERENTIAL_LEUCOCYTE_COUNT1
WHERE PATIENT_NUM = HMTLY_PATIENT_NUM AND PATIENT_NUM = DLC_PATIENT_NUM AND PATIENT_NUM
= &PATIENT_NUM;
RESULT GOT:
&PATIENT_NUM =1
no rows selected
&PATIENT_NUM=2
no rows selected
&PATIENT_NUM=3
PATIENT_NUM 3
PATIENT_NAME KKKK
HMTLY_TEST_NAME HAEMATOLOGY
HMTLY_RBC_VALUE 4
HMTLY_RBC_NORMAL 4.6-6.0
DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
DLC_POLYMORPHS_VALUE 60
DLC_POLYMORPHS_NORMAL_VALUE 40-65
ACTUAL WILL BE:
&PATIENT_NUM=1
PATIENT_NUM 1
PATIENT_NAME BBBB
HMTLY_TEST_NAME HAEMATOLOGY
HMTLY_RBC_VALUE 5
HMTLY_RBC_NORMAL 4.6-6.0
&PATIENT_NUM=2
PATIENT_NUM 2
PATIENT_NAME GGGG
DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
DLC_POLYMORPHS_VALUE 42
DLC_POLYMORPHS_NORMAL_VALUE 40-65
&PATIENT_NUM=3
PATIENT_NUM 3
PATIENT_NAME KKKK
HMTLY_TEST_NAME HAEMATOLOGY
HMTLY_RBC_VALUE 4
HMTLY_RBC_NORMAL 4.6-6.0
DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
DLC_POLYMORPHS_VALUE 60
DLC_POLYMORPHS_NORMAL_VALUE 40-65
4 TABLES FOR CLINICAL LAB FOR INPUT DATA AND GET REPORT ONLY FOR TESTS MADE FOR PARTICULAR
PATIENT.
TABLE1:PATIENTS_MASTER1
COLUMNS:PATIENT_NUM, PATIENT_NAME,
VALUES:
PATIENT_NUM
1
2
3
4
PATIENT_NAME
BBBB
GGGG
KKKK
PPPP
TABLE2:TESTS_MASTER1
COLUMNS:TEST_NUM, TEST_NAME
VALUES:
TEST_NUM
1
2
TEST_NAME
HAEMATOLOGY
DIFFERENTIAL LEUCOCYTE COUNT
TABLE3:HAEMATOLOGY1
COLUMNS:
HMTLY_NUM,HMTLY_PATIENT_NUM,HMTLY_TEST_NAME,HMTLY_RBC_VALUE,HMTLY_RBC_NORMAL_VALUE
VALUES:
HMTLY_NUM
1
2
HMTLY_PATIENT_NUM
1
3
MTLY_TEST_NAME
HAEMATOLOGY
HAEMATOLOGY
HMTLY_RBC_VALUE
5
4
HMTLY_RBC_NORMAL_VALUE
4.6-6.0
4.6-6.0
TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
COLUMNS:DLC_NUM,DLC_PATIENT_NUM,DLC_TEST_NAME,DLC_POLYMORPHS_VALUE,DLC_POLYMORPHS_
NORMAL_VALUE,
VALUES:
DLC_NUM
1
2
DLC_PATIENT_NUM
2
3
DLC_TEST_NAME
DIFFERENTIAL LEUCOCYTE COUNT
DIFFERENTIAL LEUCOCYTE COUNT
DLC_POLYMORPHS_VALUE
42
60
DLC_POLYMORPHS_NORMAL_VALUE
40-65
40-65
THANKS
RCS
E-MAIL:[email protected]
--------I think you want an OUTER JOIN
SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
DLC_POLYMORPHS_NORMAL_VALUE
FROM PATIENTS_MASTER1, HAEMATOLOGY1, DIFFERENTIAL_LEUCOCYTE_COUNT1
WHERE PATIENT_NUM = HMTLY_PATIENT_NUM (+)
AND PATIENT_NUM = DLC_PATIENT_NUM (+)
AND PATIENT_NUM = &PATIENT_NUM;Edited by: shoblock on Nov 5, 2008 12:17 PM
outer join marks became stupid emoticons or something. attempting to fix -
Is EJB query language supports UNION
Hi All,
Can anyone suggest me is EJB query language supports UNION type of select queries
if possible can any one suggest me how to convert below Sql query to Ejb ql
Ex:
select * from table1 where id='10'
union all
select * from table1 where id='20'The UNION clause specifies a combination of the output of two subqueries. The two queries must return the same number of elements and compatible types
1.You cannot use dependent value objects with UNION.
2.UNION ALL combines all results together in a single collection.
3.UNION combines results but eliminates duplicates.
4.If ORDER BY is used together with UNION, the ORDER BY
must refer to selection expression using integer numbers.
Example:
This example returns a collection of all employee objects of type EmpBean and all manager objects of type ManagerBean where ManagerBean is a subtype of EmpBean.
select e from EmpBean e union all select m from DeptBean d, in(d.mgr) mThis example shows a query that is not valid, because EmpBean and DeptBean are not compatible.
select e from EmpBean e union all select d from DeptBean d
Your Example:
Select e from Table1Bean e where e.id=10
union all
Select e from Table1Bean e where e.id=10 -
Query problem in EJB 3.0
Hi everyone I am actually using EJB3.0 in my application and am writing the queries.
I have 3 tables which are joined.
Projects - > TaskGroups -> Task
I am in my task bean and am writing the query. My query is as below
@NamedQuery(name = "getProjectTasks", query = "select o from Tasks o, TaskGroups taskgp, Projects pro where o.TaskGroups = taskgp and taskgp.project = pro")
Like that am willing to get all my tasks which are related to my projects. But am getting the following error
Multiple declaration of identification variable [o], previously declared as [Tasks o].
Can anyone help me
Regards
LutchumayaHi,
the query seems wrong. However, please ask this on the J2EE and TopLink forum
OC4J
TopLink/JPA
Frank -
EJB classpath problem when refering a DAO in library jar file
Hi
When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
Thanks in Advance
Best Regards
Venugopal BaluHi
When I tried to deploy an EJB jar file in 10g which references the DAO for getting database[SQL Server2000] query results.Its not retriving data nor throwing any exceptions.Other DAO business methods which do not access database are working well.
When I tried to import the DAO inside a JSP and calling the DAO data access method which is working fine. Even I have set the resource-ref [datasource JNDI Name] in ejb-jar.xml files for the EJB beans, but its not referencing. If you have any ideas, how to resolve this problem, please forward me your suggestion.
Thanks in Advance
Best Regards
Venugopal Balu -
I am developing an Enterprise application that uses JPA and toplink as the persistence provider. It uses MYSQL 5.1.
The query used in the Entity class is :
@NamedQueries({@NamedQuery(name = "AirtravelsDynamic.findAllEconomyFlights", query = "select NEW com.inter.transfer.Response(rf.flightno,d.economyseats,rf.ecofare,rf.arrtime,rf.depttime) from AirtravelsDynamic d LEFT JOIN d.refId rf where rf.source=?1 and rf.destination=?2 and d.availdate between ?3 and ?4") })
This application is giving the following exception:
Exception Description: Error compiling the query [AirtravelsDynamic.findAllEconomyFlights: select NEW com.inter.transfer.Response(rf.flightno,d.economyseats,rf.ecofare,rf.arrtime,rf.depttime) from AirtravelsDynamic d LEFT JOIN d.refId rf where rf.source=?1 and rf.destination=?2 and d.availdate between ?3 and ?4], line 1, column 40: invalid navigation expression [rf.flightno], cannot navigate expression [rf] of type [int] inside a query.
Local Exception Stack:
Exception [TOPLINK-8029] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [AirtravelsDynamic.findAllEconomyFlights: select NEW com.inter.transfer.Response(rf.flightno,d.economyseats,rf.ecofare,rf.arrtime,rf.depttime) from AirtravelsDynamic d LEFT JOIN d.refId rf where rf.source=?1 and rf.destination=?2 and d.availdate between ?3 and ?4], line 1, column 40: invalid navigation expression [rf.flightno], cannot navigate expression [rf] of type [int] inside a query.
at oracle.toplink.essentials.exceptions.EJBQLException.invalidNavigation(EJBQLException.java:430)
at oracle.toplink.essentials.internal.parsing.DotNode.checkNavigation(DotNode.java:141)
at oracle.toplink.essentials.internal.parsing.DotNode.validate(DotNode.java:97)
at oracle.toplink.essentials.internal.parsing.ConstructorNode.validate(ConstructorNode.java:97)
at oracle.toplink.essentials.internal.parsing.SelectNode.validate(SelectNode.java:329)
at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:229)
at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:211)
at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:201)
at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateReadQueryInternal(EJBQLParseTree.java:134)
at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateQuery(EJBQLParseTree.java:108)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:219)
at oracle.toplink.essentials.queryframework.EJBQLPlaceHolderQuery.processEjbQLQuery(EJBQLPlaceHolderQuery.java:111)
at oracle.toplink.essentials.internal.sessions.AbstractSession.processEJBQLQueries(AbstractSession.java:2059)
at oracle.toplink.essentials.internal.sessions.AbstractSession.processEJBQLQueries(AbstractSession.java:2046)
at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:724)
at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:604)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:280)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:229)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:93)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:126)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:120)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:91)
Any help is appreciated.
Thanks in advance.What are you trying to do exactly? The way you've used LEFT JOIN is not correct if d.refId is an integer. LEFT JOIN is used to retrieve a set of entities where that set may not exist. It doesn't look like refId is a set of anything, just an integer.
It looks like maybe you intended to have a foreign key relationship between AirtravelsDynamic and some other entity. In that case you probably want to model your AirtravelsDynamic entity as having a many-to-one relationship with the entity (let's call it ref.)
The relationship would look something like:
@Entity
public class AirtravelsDynamic
@ManyToOne
@JoinColumn(name="refId")
private Ref ref;
}Then your query would read:
SELECT new com.inter.transfer.Response(d.ref.flightno, d.economyseats,
d.ref.ecofare, d.ref.arrtime,
d.ref.depttime)
FROM AirtravelsDynamic d
WHERE d.ref.source = :refSource
AND d.ref.destination = :refDest
AND d.availDate between :lowDate and :highDateIf I'm misunderstanding your intent, let me know and I'll try to help you resolve the problem. -
I am running JDev 11g patch 2 (11...3) on a windows 7 machine. JDK 1.6_18
@NamedNativeQueries({
@NamedNativeQuery(name = "MenuFolders.findFolderByUser",
query = "SELECT * FROM menu_folders where mf_id is null and id in (select mf_id from userfoldervw where UPPER(user_name) = :p_user) order by display_order",
resultClass = MenuFolders.class)
I have entered the above code in to a entity bean - but all I get back when I run is invalid SQL statement - it works fine in a sql window.
I tried to use just "SELECT * FROM menu_folders " and get the same problem. Many of the examples show the same format as in the namedQuery ("select o from menuFolders o") but I thought the principle of native querys was to use standard SQL - just for this reason - not everything can be done in sql expression language.
Two things 1) mf_id is self referencing and there is no definition for the column in the regular EJB code. 2) userfoldervw is outside the bean (and yes it is a view)
There is a secondary issue - this is a master for another table which holds the actual items (forms).
I want to build a menu tree - normally I would do this in a backing bean and problematically build the tree menu - however - with JDeveloper this does not appear to be an option.
I have the system working fine in the Netbeans IDE using the backing bean.
I was looking for the adfMenuTree (the adfTree does not have the folder/node concept. I cannot find sufficient info on the adfTree to understand how it manages levels to make any sense out of it.)
Can someone give me a hand on this (either a backing bean solution with the adfTree or a view object - or just the sql)?I have been developing with NetBeans and find it a much simpler IDE to work with but it is not time to move on.
The project I have been working on has a basic splash screen -> Login -> Menu structure.
The menu is based on a workflow and role concept. In the login I capture the users roles and the location code. These are stored in a session bean.
The username and the location code then govern the items in the menu and a to do list that is in a split panel (menu on left and to dos on the right with a button that takes them to the appropriate page based on workflow)
The issue I had with ADF was the lack of a data control in the page - I was using pure JSF. When I looked at the backing bean in the debugger - the input text was not being passed to the backing bean.
I was able to solve this by a bit of editing in the jsp and some movement in the locations. What I found interesting was that the methods in the backing bean worked fine (with the NPE due to the lack of the binding of the input text to the backing bean).
I am trying to move my skills into ADF/JDeveloper - and finding that it is a very obtuse IDE. The focus seems to be on technology rather than application development.
I came from the Oracle Forms/Reports environment and used the Designer2000 extensively - the focus was only on the business logic - the rest was generated for you.
With NetBeans - I found a similar focus. JDeveloper however is a different animal - I have spent hours and read tons of material - and still cannot find answers to very simple things.
I have a good example - I have a view object that takes a parameter - it looks to me like I will have to write over 100 lines of code to get this to work and I an still not sure how I will manage it in a backing bean.
I have no control - other than a button to execute a method (Netbeans had an abstract page bean that exposed parts of the life cycle (init, prerender, etc ...) that allowed me to execute code at specific life cycle stages - I have not found anything at all in the ADF that would guide me in doing the same.
According to all the documentation I have read (considerable) I will have to defeat ADF and do everything programatically - what a waste of good technology and my time.
I may be wrong - I hope I am - maybe some one can point me into a direction that can help me with this (everything in the tutorials misses these simple issues that we use every day). -
Reg: Query Problem for New Posting Period
Hi Xperts,
While I try to Map the A/P Invoices with their respective Outgoing Payment,
I used the following Query and it's Query Printlayout
SELECT T0.DocNum [Payment#], T0.DocDate [Payment Date],
T0.CardCode, T0.CardName, T1.InvoiceId, T2.DocNum [AP Inv#],
T2.NumatCard [Bill No.], T2.DocDate [Bill Date], T1.selfInv,
T1.SumApplied, T1.WtAppld, T0.NoDocsum
FROM [dbo].[OVPM] T0 INNER JOIN
[dbo].[VPM2] T1 ON T1.[DocNum] = T0.DocNum
INNER JOIN [dbo].[OPCH] T2 ON T2.[DocEntry] = T1.DocEntry
WHERE T0.Cardname='[%0]' and T0.DocDate='[%1]' and
T0.DocNum='[%2]'
I got the above query from our Expert Mr.Sambath only.
Now what is the problem is the query is retrieving the payment details of old Posting Period only and not the current posting period.
In detail, I used 'Primary' Series for FY08-09, Period indicator 'Default'
Now I'm using 'Primary1' Series for FY09-10, Period indicator '0910'
Thanx in adv.
Regards,
BalaHi Bala,
Looking at your query, it is not query issue ,it is your data issue.
Please check if you have data in VPM2 table which is bank transfer payment method
Thank you
Bishal
Edited by: Bishal Adhikari on Apr 9, 2009 8:48 AM -
Hi Greg,
I had created a view on a table which doesn't have Primary Key, but it has Unique and Not Null constraints on required columns.
I had wrote a procedure to query the data on VIEW. I have experienced strange problem, very first call to procedure will take more time than succeeding requests. For example from second request onwards, it returns data in < 2 Sec, but first transaction is taking 12 Sec to 30 Sec.
I thought that very first time VIEW is taking time to refresh it self. So, I added FORCE keyword in CREATE VIEW stattement. However, that doesn't helped out.
In my further investigation I came to know that base table on which VIEW created, has to be loaded in to memory before querying on VIEW.
So, I had executed a simple select statement on base table, before I execute VIEW query in procedure.
With this change I got results consistently < 2 Sec all the times.
My question is instead of executing the select statement on base table is there a way to load base tables data in memory before querying on VIEW?
Thanks,
SubbaraoHi,
A view is nothing but parsed SQL statements stored in the database, a view may or may not run faster. If you execute the SQL used to define the view how much time is it taking. If you want try looking at MATERIALIZED VIEW , that may help you.
thanks -
Date range query problem in report
Hi all,
I have created a report based on query and i want to put date range selection but query giving problem.
If i am creating select list selection then it is working fine means it will display all records on the particular date.
But what i need is that user will enter date range as creation_date1,creation_date2 and query should return all the records between these date range. i want to pass it by creating items, i created two items and passing creation_date range to display all records but not displaying and if not passing date then should take null as default and display all records
Here is the query:
/* Formatted on 2006/12/10 20:01 (Formatter Plus v4.8.0) */
SELECT tsh."SR_HEADER_ID", tsh."SALES_DEPT_NUMBER", tsh."COUNTRY",
tsh."LOCAL_REPORT_NUMBER", tsh."ISSUE_DATE", tsh."SUBJECT",
tsh."MACHINE_SERIAL_NUMBER", tsh."MACHINE_TYPE", tsh."MACHINE_HOURS",
tsh."STATUS"
FROM "TRX_SR_HEADERS" tsh, "TRX_SR_PARTS" tsp
WHERE (tsh.status LIKE :p23_status_sp OR tsh.status IS NULL)
AND (tsh.machine_type LIKE :p23_machine_type_sp)
AND ( tsh.machine_serial_number LIKE
TO_CHAR (:p23_machine_serial_number_sp)
OR tsh.machine_serial_number IS NULL
AND ( TO_CHAR (tsh.failure_date, 'DD-MON-YY') LIKE
TO_CHAR (:p23_failure_date_sp)
OR TO_CHAR (tsh.failure_date, 'DD-MON-YY') IS NULL
AND ( TO_CHAR (tsh.creation_date, 'DD-MON-YY')
BETWEEN TO_CHAR (:p23_creation_date_sp)
AND TO_CHAR (:p23_creation_date_sp1)
OR TO_CHAR (tsh.creation_date, 'DD-MON-YY') IS NULL
AND (tsh.issue_date LIKE :p23_date_of_issue_sp OR tsh.issue_date IS NULL)
AND (tsh.country LIKE :p23_country_sp OR tsh.country IS NULL)
AND ( tsh.local_report_number LIKE TO_CHAR (:p23_local_rep_num_sp)
OR tsh.local_report_number IS NULL
AND ( tsp.part_number LIKE TO_CHAR (:p23_part_number_sp)
OR tsp.part_number IS NULL
AND tsh.machine_type IN (
SELECT DISTINCT machine_type
FROM trx_sales_dept_machine_list
WHERE sales_department_id IN (
SELECT DISTINCT sales_department_id
FROM trx_user_sales_department
WHERE UPPER (user_name) =
UPPER ('&APP_USER.'))
AND SYSDATE >= valid_from)
AND tsh.sr_header_id = tsp.sr_header_id
can any one tell me wat is wroung in this query.
Any other way to write this?
Thank You,
AmitHi User....
Here is some date range SQL that my teams uses with some success:
For date columns that do not contain NULL values, try this (note the TRUNC, it might help with your "today" problem).
The hard coded dates allow users to leave the FROM and TO dates blank and still get sensible results (ie a blank TO date field asks for all dates in the future.
AND TRUNC(DATE_IN_DATABASE)
BETWEEN
decode( :P1_DATE_FROM,
TO_DATE('01-JAN-1900'),
:P1_DATE_FROM)
AND
decode( :P1_DATE_TO,
TO_DATE('31-DEC-3000'),:
:P1_DATE_TO)
For date columns that contain NULL values, try this (a little bit trickier):
AND nvl(TRUNC(DATE_IN_DATABASE),
decode( :P1_DATE_FROM,
decode( :P1_DATE_TO,
TO_DATE('30-DEC-3000'),
NULL),
NULL)
BETWEEN
decode( :P1_DATE_FROM,
TO_DATE('01-JAN-1900'),
:P1_DATE_FROM)
AND
decode( :P1_DATE_TO,
TO_DATE('31-DEC-3000'),
:P1_DATE_TO)
Note the 30-DEC-3000 versus 31-DEC-3000. This trick returns the NULL dates when the FROM and TO date range items are both blank.
I hope this helps.
By the way, does anyone have a better way of doing this? The requirement is given a date column in a database and a FROM and a TO date item on a page,
find all of the dates in the database between the FROM and TO dates. If the FROM date is blank, assume the user want all dates in the past (excluding NULL dates). If the TO date is blank, assume that the user wants all of the dates in the future (excluding NULL dates). If both FROM and TO dates are blank, return all of the dates in the databse (including NULL dates).
Cheers,
Patrick -
Hi Gurus,
The scenario is that there are 2 inficubes, one with order data and other with delivery data. The cube with order data has the requested delivery date and the delivery cube has the actual delivery date. The problem is that I have a query on a multiprovider (on top of the 2 cubes). So when I output the query data by the sales order number, the result is fine, but when I drill down on any of the dates mentioned above ( they are free characteristics in the query), the result splits up into 2 records. For Eg.
Sales Order Req Del Date Act Del Date Order Qty Shipped Qty
12345 03/03/08 - 5 -
- 06/03/08 - 5
What can I do to get the result in one row?
I will reward points for any help.
ThanksThis is the behavior of the multiprovider, since the actual goods issue date is not part of the orders cube, then it will create a second record. There are a couple solutions you could get around to this:
1. You could merge the data in one DSO before you actually load it to the data target. To do this, you could update fields you need to the orders ods from the delivery ods.
2. You could create an infoset between the two cubes if you are in 7.0, otherwise, you could create infoset using the underlying ods and create a query from the infoset: performance wise this is not recommended.
3. If you want to solve the issue report level, there is what is called constant selection and you can make the actual goods issue date as a constant selection and you can get one line.
/people/prakash.darji/blog/2006/09/19/the-hidden-secret-of-constant-selection
I would recommend the last option,
thanks.
Wond -
Out standing MIS Report query problem.
Hi,
We designed MIS Report for outstanding mis through Crystal report.here we are facing probleme.ex:AR invoice raised on 01 Jan 09 bill amount 1000 and for this client is received full amount against that bill on 04 march09.in this report we provided parameters for from date and to date. When user selected in parameter from date 010109 to 050309 it will show pending amount is 0.but users are asking if they select from date upto 030309 means it will show pending amount should be show 1000.in this query we are retrieving based on document status when open. How we can show report for this requirements. Please guide me.if we give docstatus='O' or docstatus= 'C' it's showing but pending amount =Bill amount - paid amount here it's showing 0 i think here also we need to pass incoming payment docdate.how wen do please guide me.
below this is the query.
set @FromYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate)-1 else Year(@ToDate) end
set @ToYear=case when month(@ToDate)>=1 and month(@ToDate)<=3 then Year(@ToDate) else Year(@ToDate)+1 end
--select @fromYear,@toyear,@todate,@ProjCode,@Cardcode,@VoucherType,@GroupName
select a.u_category,a.docdate,g.name,d.CardCode,d.cardname,e.GroupName,SUBSTRING(CONVERT(VARCHAR(11), a.docdate, 113), 4, 8)as Month of invoiceraised,
b.seriesname,a.docnum,a.Project,0,a.doctotal,
paidamount= case when a.paidtodate is NULL then 0 else a.paidtodate end,
pendingamount= case when isnull(a.doctotal,0)-isnull(a.paidtodate,0) is null then 0 else isnull(a.doctotal,0)-isnull(a.paidtodate,0) end,
case when year(a.docdate) = @ToYear and month(a.docdate) = 3 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as March ,
case when year(a.docdate) = @ToYear and month(a.docdate) = 2 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Feb,
case when year(a.docdate) = @ToYear and month(a.docdate) = 1 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Jan,
case when year(a.docdate) = @FromYear and month(a.docdate) = 12 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Dec,
case when year(a.docdate) = @FromYear and month(a.docdate) = 11 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Nov,
case when year(a.docdate) = @FromYear and month(a.docdate) = 10 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Oct,
case when year(a.docdate) = @FromYear and month(a.docdate) = 9 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Sept,
case when year(a.docdate) = @FromYear and month(a.docdate) = 8 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as Aug,
case when year(a.docdate) = @FromYear and month(a.docdate) = 7 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as July,
case when year(a.docdate) = @FromYear and month(a.docdate) = 6 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as June,
case when year(a.docdate) = @FromYear and month(a.docdate) = 5 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as May,
case when year(a.docdate) = @FromYear and month(a.docdate) = 4 then isnull(a.doctotal,0)-isnull(a.paidtodate,0) else 0 end as April,
--case when a.docdate = (select f_refdate from ofpr where year(f_refdate)=year(a.refdate) then a.doctotal-c.paidtodate else 0 end as Pre-Yr
nodocsum=isnull(f.nodocsum,0),0 as PreviousFY
from oinv a
left join nnm1 b on a.series=b.series
inner join INV1 c ON a.DocEntry = c.DocEntry
inner join OCRD d ON d.CardCode=a.CardCode
left join ocpr g on g.cardcode=d.cardcode
Inner join OCRG e on e.GroupCode=d.GroupCode and e.grouptype='c'
LEFT JOIN ORCT f ON a.DocEntry = f.DocEntry
where
a.docstatus='O' and
case when a.doctotal-a.paidtodate is null then 0 else a.doctotal-a.paidtodate end >= 0
Reds,
Sampath kumar devunuri.Hi,Gordon Du ,
We are designing through Crystal reports 2008 only. Based on SQL query how we can maintain History of Document status and date in table. Please give me your advise how we can rectify this problem. Kindly find above query.
Regds,
Sampath Kumar. -
Query problem with accumulated key figures
Hi BI Gurus!
I have a report problem that I hope you can help me with!
In my report I have 2 key figures. One for accumulated revenue previous year (KF1) and one for accumulated revenue current year (KF2). Both key figures should be presented in a graph in monthly buckets.
January figures from both the key figures shoule be presented in the same bucket. Therfore I can't use 0CALYEAR since we have the "year" information in there. Instead I'm using 0CALMONTH2 which is only two digits, 01 for January. That way I can map figures from both previous year and current year in the same bucket.
I need the figures to be accumulated and this is what I have problem with. When I run the report today in February 2010 it looks like this:
Month KF1 KF2
01 10 15
02 10 20
03 15
04 10
05 20
06 10
07 10
08 15
09 15
10 20
11 20
12 10
This is how I would like the report to look like:
Month KF1 KF2
01 10 15
02 20 35
03 35
04 45
05 65
06 75
07 85
08 100
09 115
10 135
11 155
12 165
I have tried to use the setting "accumulated" for the key figures but then I get this result:
Month KF1 KF2
01 10 15
02 20 35
03 35 35
04 45 35
05 65 35
06 75 35
07 85 35
08 100 35
09 115 35
10 135 35
11 155 35
12 165 35
Since the KF2 is revenue for current year and I run the report in February I don't want any figures to be displayed in Mars...
I have tried to restrict the key figures by 0CALMONTH2 and 0CALYEAR. The KF1 is havein a restriction to only show values for 0CALYEAR - 1 and an interval for 0CALMONTH2 from JAN - DEC.
The KF2 is having a restriction to only show values in the interval "first month in year - current month" (in this example JAN - FEB) for 0CALMONTH2. And current year for 0CALYEAR.
Despite my restrictions for KF2 the numpers repeats itself for every month...
Any suggestion how I can resolve this?
Best regards
Anders FlorinHi Khaled and thank you for trying to help me!
I agree with you and think the users should accept the report as it is. But they are claiming that top management will not accept this and they would really want this to be fixed the whay that they want. I have tried to push back on this and said that I'm not sure that it can be resoleved and that it could cost them a lot of money if I try.
But I will try to resolve it for them if I have spare time in the end of the project. I have not promised them anything but it would really be nice if I could fix it.
So when you say I need to use a structure and a calculated key figure. How should the calculated key figure and the structure be configured?
If I use a structure in the rows I guess I can't use same object in calc.key.figure right? Like if I use 0CALMONTH2 in the structure I'm not able to restrict the key figure with the same object? If that is correct I also have a ZMONTH object, different story why I have that... , that I can use in the same way as 0CALMONTH2. Or is this only a problem when I use "local" formulas within the query and not using a "global" calculated key figure? Cause I have only used the "loacal" formula calculated key figure in this report....
Br
Anders
Maybe you are looking for
-
How to submit the report in Background job.
Hello Friends, In the selection screen I have 2 radio buttons one for background Process & other for foreground processing. if the user selects the background processing the program should execute in background and output need to be sent to SAP Inbox
-
Help. 3D isn´t working in CS6 after update. open GL
I just updated my photoshop to the latest version provided in the application manager. i created a 3D document in front, had no problems except 1 crash while working with 3D layers. now it won´t let me open this psd becaus Open GL is not activated. N
-
Is it possible to load transaction with multiple batch_source_name??
Hi, I am calling 'Autoinvoice Master Program' for creating transactions in my custom package. I have 15 lines in my data file. They are invoices, credit memos, debit memos with different batch_source_name. Import program is picking tranasctions with
-
What does transition type mean
What does transition type mean under slide show settings?
-
How do I synchronize two processes on two different PC's ?
I have a master and slave computer with a vi running on each, periodically these processes will need to be synchronized. If the processes were running as separate threads on the same PC, I know could use the LabVIEW rendezvous technology to do this.