SQLAssembler id-query

Hello all,
I have stumbled across a problem I ran across previously but I don't know how to fix the problem.
I have an insert query in my SQLAssembler that inserts a record into our Oracle database. I have an id-query that gets the currval from a sequence for the primary key of the new record:
<create-item>
<sql>
INSERT INTO WORK_QUEUE (WORK_QUEUE_ID, CREATION_DATE, DESCRIPTION) VALUES
(#WORK_QUEUE_ID#, TO_DATE(#CREATION_DATE#, 'MM/DD/YYYY'), #DESCRIPTION#)
</sql>
<id-query>SELECT SUBSCRIBER_ID_SEQ.CURRVAL FROM DUAL</id-query>
</create-item>
where WORK_QUEUE_ID is the primary key. When this query gets called I get the following error:
18:02:23,090 INFO  [STDOUT] lcds[DEBUG] [Service.Data.SQL] SQL Assembler jdbc exception on operation=create-item error=java.sql.SQLException: ORA-08002: sequence SUBSCRIBER_ID_SEQ.CURRVAL is not yet defined in this session
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:810)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:85 0)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1134)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3 339)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3384 )
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStat ement.java:342)
at flex.data.assemblers.SQLAssembler.processIdQuery(SQLAssembler.java:1069)
at flex.data.assemblers.SQLAssembler.createItem(SQLAssembler.java:1020)
at flex.data.adapters.JavaAdapter.doCreateItem(JavaAdapter.java:1829)
at flex.data.adapters.JavaAdapter.invokeAssemblerSync(JavaAdapter.java:1698)
at flex.data.adapters.JavaAdapter.invokeBatchOperation(JavaAdapter.java:1562)
at flex.data.adapters.JavaAdapter.invoke(JavaAdapter.java:636)
at flex.messaging.services.MessageService.serviceMessage(MessageService.java:276)
at flex.data.DataService.sendBatchToAdapter(DataService.java:1414)
at flex.data.DataService.serviceTransactedMessage(DataService.java:787)
at flex.data.DataService.serviceMessage(DataService.java:465)
at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1503)
at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:898)
at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:121)
at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)
at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:147)
at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:278)
at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:322)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.ja va:190)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at flex.messaging.security.TomcatValve.invoke(TomcatValve.java:151)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEs tablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEst ablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java: 158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.ja va:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
I found that this error happens because I am trying to use CURRVAL before using NEXTVAL according to the Oracle site. But I don't understand why this is happening when it is. If I perform an action that uses a similar insert and id-query, I do not get that error and the new row is added correctly.
Does anyone know why this is happening? Has anyone run into this problem before?

For LCDS documentation is not very clear. Try to edit newDependent added before adding to the collection. If you want to edit later, then take it from the collection, after finnish, commit changes.
However it is not usual to add a object to collection and then edit it immediately. Not very logical in terms of how the application is built.

Similar Messages

  • Publish SQL as a WEB Service from Database (10.2) using OC4J (without JDev)

    Hi,
    I have been successfull in Publishing Web Service using SQL (DML) using :
    1. Oracle Express Db 10.2
    2. OC4J 10.1.3
    Any Help Will be appreciated........ :)
    NOTE: Oracle Documentation on Application Server SUCKS (Too Many Errors prints and Wrong Information in the Web Servises area including JAR file paths)
    I can only use One parameter in the QUERY and a Second Parameter gives an Error.
    java -jar ${ORACLE_HOME}/webservices/lib/wsa.jar -sqlAssemble -appName query -dataSource jdbc/OracleCoreDS -sqlstatement "updtProdTyp=update PRODUCT_TYPES SET NAME = :{newname VARCHAR} where NAME = :{oldname VARCHAR}" -dbConnection jdbc:oracle:thin:@localhost:1521:XE -dbUser store/store
    INFO: [WSADBPlugin] endpoint setInterface: oracle.generated.SqlStmts, setImplementation: oracle.generated.SqlStmtsUser
    INFO: java oracle.jpub.Doit -user=store/store -url=jdbc:oracle:thin:@localhost:1521:XE -dir=./src/server -codegen=jdbc -style=oracle/j2ee/ws/tools/wsa/db/webservices-common -style=oracle/j2ee/ws/tools/wsa/db/webservices10 -style=oracle/j2ee/ws/tools/wsa/db/webservices10literal -outarguments=return -datasource=jdbc/OracleCoreDS -sqlstatement.updtProdTyp=update PRODUCT_TYPES SET NAME = :{newname VARCHAR} where NAME = :{oldname VARCHAR} -sqlstatement.class=SqlStmts -package=oracle.generated -plsqlfile=SqlStmts_plsql_wrapper.sql,SqlStmts_plsql_dropper.sql -plsqlpackage=SqlStmts_plsql_wrapper -connscope=method -sqlj -d=./war/WEB-INF/classes -C-g
    INFO: SqlStmtsBase
    /usr/lib/oracle/xe/app/OC4J/D_My_Apps/src/server/oracle/generated/SqlStmtsUser.java:8: oracle.generated.SqlStmtsUser is not abstract and does not override abstract method updtProdTypiSS(java.lang.String[],java.lang.String[]) in oracle.generated.SqlStmts
    public class SqlStmtsUser extends SqlStmtsBase implements SqlStmts, java.rmi.Remote
    ^
    /usr/lib/oracle/xe/app/OC4J/D_My_Apps/src/server/oracle/generated/SqlStmtsUser.java:22: cannot find symbol
    symbol : method _getProdTypBeans(java.lang.String,java.sql.Connection)
    location: class oracle.generated.SqlStmtsBase
    __jRt_0 = super._getProdTypBeans(__jRt_2, __onnScopeMethod);
    /usr/lib/oracle/xe/app/OC4J/D_My_Apps/src/server/oracle/generated/SqlStmtsUser.java:85: cannot find symbol
    symbol : method _getProdTyp(java.lang.String,java.sql.Connection)
    location: class oracle.generated.SqlStmtsBase
    __jRt_0 = super._getProdTyp(__jRt_8, __onnScopeMethod);
    ^
    /usr/lib/oracle/xe/app/OC4J/D_My_Apps/src/server/oracle/generated/SqlStmtsUser.java:128: _updtProdTyp(java.lang.String,java.lang.String,java.sql.Connection) in oracle.generated.SqlStmtsBase cannot be applied to (java.lang.String,java.sql.Connection)
    __jRt_0 = super._updtProdTyp(__jRt_10, __onnScopeMethod);
    ^
    /usr/lib/oracle/xe/app/OC4J/D_My_Apps/src/server/oracle/generated/SqlStmtsUser.java:145: cannot find symbol
    symbol : method _updtProdTypiS(java.lang.String[],java.sql.Connection)
    location: class oracle.generated.SqlStmtsBase
    __jRt_0 = super._updtProdTypiS(__jRt_12, __onnScopeMethod);
    ^
    6 errors
    INFO: NEW DBWS runtimeProperties set databaseJndiName: jdbc/OracleCoreDS
    INFO: User classpath is :/usr/lib/oracle/xe/app/OC4J/D_My_Apps/./war/WEB-INF/classes
    INFO: Checking for JSR-181 Annotations capabilities in current JVM...
    INFO: Found JSR-181 Annotations capabilities. Checking for JSR-181 Annotations Processor...
    INFO: Found JSR-181 Annotations processor. JSR-181 Annotations (if any) will be processed
    INFO: No JSR-181 annotations found in specified class oracle.generated.SqlStmtsUser
    FINE: ValueTypeModeler.log [creating model: query]
    FINE: ValueTypeModeler.log [creating port: oracle.generated.SqlStmts]
    FINE: MethodModeler.log [creating operation: updtProdTyp]
    FINE: MethodModeler.log [creating operation: updtProdTypiSS]
    WARNING: Problem validating implementation class. Access modifier problem detected for the implementation class oracle.generated.SqlStmtsUser: int updtProdTyp( java.lang.String, java.lang.String ) is defined with access modifiers that make it an unsuitable implementation of the interface method: The method cannot be 'abstract'.
    Thu Mar 30 14:17:34
    Thanks
    ====================================

    I don't have the problem with the second arugument, using essentially the same command as yours. Could you make sure you clean up the following subdirectories and retry:
    ear query.ear src war
    My guess is that the leftover subdirectories in your previous run are playing game with you. You can simplify leftover management by specifying -output setting.

  • SQLAssembler: Handling dates

    I'm just wondering if anyone has had any luck using date/time
    fields with SQLAssembler, as I'm having a few problems.
    My update query declaration looks like this:
    <update-item>
    <sql>UPDATE Timesheet SET person=#person#,
    <sniiiiip, lots of fields>, date=#date# WHERE id=#_PREV.id#
    </sql>
    </update-item>
    I'm editing the data from the DataService with an item
    editor, which looks something like this:
    <mx:itemEditor>
    <mx:Component><mx:DateField
    formatString="DD/MM/YYYY"/></mx:Component>
    </mx:itemEditor>
    I'm using an actionscript-class declaration in the
    SQLAssembler config, and it that class the var named "date" is of
    type Date.
    My database is an Access MDB connecting with
    sun.jdbc.odbc.JdbcOdbcDriver.
    If I remove the part which sets the date field (date=#date#)
    from my update query, everything works perfectly.
    I have LCDS set to show all debug messages, and this is the
    error shown when I exit the date field after changing it:
    When I set editorDataField="selectedDate" I get the following
    error:
    [Flex] 16:19:50.468 [DEBUG] [Service.Data.SQL] SQL Assembler
    jdbc exception on operation=update-item
    error=java.sql.SQLException: SQL Exception : Unknown SQL Type for
    PreparedStatement.setObject (SQL Type=1111
    And if I set editorDataField="text" (which appears to cause
    the format string to be applied according to the rtmp message
    intercepts), then I get this:
    [Flex] 16:27:23.500 [DEBUG] [Service.Data.SQL] SQL Assembler
    jdbc exception on operation=update-item
    error=java.sql.SQLException: [Microsoft][ODBC Microsoft Access
    Driver] Syntax error in UPDATE statement.
    And if I then add single quotes around the date field in the
    update query ( date='#date#' ), I get this:
    [Flex] 16:32:11.156 [DEBUG] [Service.Data.SQL] SQL Assembler
    jdbc exception on operation=update-item
    error=java.sql.SQLException: Unexpected exception : 7
    I've tried various format strings which I think Access should
    handle, but they all result in the unexpected exception error. I've
    also tried changing the data type on the actionscript class to
    String but it still gives the same results.
    What would be really handy would be if I could see the exact
    query which is being run against the database to try and determine
    what is actually being entered when the error occurs.
    I've tried
    this logging jdbc driver,
    but so far I couldn't get it to work with the Access driver and the
    trouble shooting documentation is very sparse.
    If anyone has any clues on either how I can see the actual
    update query SQLAssembler is running or what I need to do to enable
    editable date fields I'd be very grateful.
    Thanks,
    Robert

    I've now tried with 2 other databases:
    MySQL works perfectly.
    MSSQL fails with the error "The Java type java.util.Date is
    not a supported type."
    So this might be a question of whether a specific JDBC driver
    can map Java's date object to a field correctly.
    EDIT:
    I tried experimenting with another JDBC driver to connect to
    MSSQL:
    jTDS
    It failed with a very similar error message, but it can be
    tweaked to map the JAVA_OBJECT type to datetime, but there may be
    side-effects of this change (e.g. another type without mapping
    available defined my now cause a class cast exception rather than
    resulting in an sql exception being raised).
    In most situations storing the date in a timestamp would be
    more appropriate than a datetime field, but as the SQLAssembler
    appears to be unable to map Timestamp to anything but ByteArray
    this solution doesn't seem feasible here. If SQLAssembler were to
    map to java.
    sql.Date instead of java.
    util.Date, this would also be undesirable as the java.sql
    version does not include the time.
    If anyone is interested in the tweaks you need to make to the
    jTDS driver then post here and I'll put the diff up, but really it
    feels "a bit dodgy" to map JAVA_OBJECT jdbc fields to date and
    probably not something you'd want to do in production for the sake
    of reliability (this is just for a small internal project at my
    company).
    Now I just need to work out how best to enable people to edit
    a time as well as the date in the DateField...

  • Error while running a query-Input for variable 'Posting Period is invalid

    Hi All,
    NOTE: This error is only cropping up when I input 12 in the posting period variable selection. If I put in any other value from 1-11 I am not getting any errors. Any ideas why this might be happening?
    I am getting the following error when I try and run a query - "Input for variable 'Posting Period (Single entry, mandatory)' is invalid" - On further clicking on this error the message displayed is as follows -
    Diagnosis
    Variable Posting Period (Single Value Entry, Mandatory) is used as a lower limit (X) and an upper limit () in an interval selection. This limit has the value #.
    System Response
    Procedure
    Enter a different value for variable Posting Period (Single Value Entry, Mandatory). If the value of the other limit is determined by another variable, you can change its value also.
    Procedure for System Administration

    OK.
    Well, if the variable is not used in any interval selection, then I would say "something happened to it".
    I would make a copy of the query and run it to check if I get the same problem with period 12.
       -> If not, something is wrong in the original query (you can proceed as below, if changes to original are permitted).
    If so, then try removing the variable completely from the query and hardcode restriction to 12.
       -> If problem still persists, I would have to do some thinking.
    If problem is gone, then add the variable again. Check.
       -> If problem is back, then the variable "is sick". Only quick thing to do, is to build an identical variable and use that one.
    If problem also happens with the new variable, then it's time to share this experience with someone else and consider raising an OSS.
    Good luck!
    Jacob
    P.S: what fisc year variant are you using?
    Edited by: Jacob Jansen on Jan 25, 2010 8:36 PM

  • Logical database in adhoc query

    Hello All,
    Can anyone tell me what is the logical database in adhoc query?

    Hi
    When you create a query , you have to select an infoset. Infoset can be considered as a source from which data is populated in the Query Fields.
    Infosets are created from Transaction SQ02.
    There can be four methods through which an Infoset can become a source of data:
    1.  Table join ( By joining two or more tables from Data dictionary)
         example: Joining tables PA0001 and PA0006 on Pernr to get a one resultant dataset
    2. Direct read of Basis Table ( Like PA0001 as a source for data in Infoset )
    3. Logical Database ( A Pre-written Program by SAP that extract data from clusters, tables taking care of authorizations and validity periods)
    Example : Logical database PNP, PNPCE (Concurrent Employement),PCH ( LDB for Personnel Development Data)
    Custom Logical DBs can be created in T_Code SE-36.
    4. Data Retrieval by a Program ( Custom code written by ABAP developers which will collect and process data) . This program has a corresponding Structure in data dictionary and the fields of this structure will be used in query)
    Reward Points, if helpful.
    Regards
    Waseem Imran

  • Query help on Goods Receipt Query with AP Invoice

    Looking for a little help on a query.  I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice).  I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start.  SBO 2005 SP01.  Any help would be great appreciated.  Thanks
    SELECT distinct 'GR',
    D0.DocStatus,
    D0.DocNum ,
    D0.DocDate,
    D0.DocDueDate,
    D0.DocTotal,
    'AP',
    I0.DocStatus,
    I0.DocNum ,
    I0.DocDate,
    I0.DocDueDate,
    I0.DocTotal,
    I0.PaidToDate
    FROM
    ((OPDN  D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
    full outer join
    (OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
    on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
    WHERE
    (D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry
    FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))

    Hi Dalen ,
    I  believe it is because of the condition
    (D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
    OR (I1.BaseType=20 AND I1.BaseEntry IN
    (SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
    Try changing
    D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
    PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
    Lets see what would be the result . Lets have some fun with troubleshooting
    See what would be the difference in the result .
    Thank you
    Bishal

  • Can you check for data in one table or another but not both in one query?

    I have a situation where I need to link two tables together but the data may be in another (archive) table or different records are in both but I want the latest record from either table:
    ACCOUNT
    AccountID     Name   
    123               John Doe
    124               Jane Donaldson           
    125               Harold Douglas    
    MARKETER_ACCOUNT
    Key     AccountID     Marketer    StartDate     EndDate
    1001     123               10526          8/3/2008     9/27/2009
    1017     123               10987          9/28/2009     12/31/4712    (high date ~ which means currently with this marketer)
    1023     124               10541          12/03/2010     12/31/4712
    ARCHIVE
    Key     AccountID     Marketer    StartDate     EndDate
    1015     124               10526          8/3/2008     12/02/2010
    1033     125               10987         01/01/2011     01/31/2012  
    So my query needs to return the following:
    123     John Doe                        10526     8/3/2008     9/27/2009
    124     Jane Donaldson             10541     12/03/2010     12/31/4712     (this is the later of the two records for this account between archive and marketer_account tables)
    125     Harold Douglas               10987          01/01/2011     01/31/2012     (he is only in archive, so get this record)
    I'm unsure how to proceed in one query.  Note that I am reading in possibly multiple accounts at a time and returning a collection back to .net
    open CURSOR_ACCT
              select AccountID
              from
                     ACCOUNT A,
                     MARKETER_ACCOUNT M,
                     ARCHIVE R
               where A.AccountID = nvl((select max(M.EndDate) from Marketer_account M2
                                                    where M2.AccountID = A.AccountID),
                                                      (select max(R.EndDate) from Archive R2
                                                    where R2.AccountID = A.AccountID)
                   and upper(A.Name) like parameter || '%'
    <can you do a NVL like this?   probably not...   I want to be able to get the MAX record for that account off the MarketerACcount table OR the max record for that account off the Archive table, but not both>
    (parameter could be "DO", so I return all names starting with DO...)

    if I understand your description I would assume that for John Dow we would expect the second row from marketer_account  ("high date ~ which means currently with this marketer"). Here is a solution with analytic functions:
    drop table account;
    drop table marketer_account;
    drop table marketer_account_archive;
    create table account (
        id number
      , name varchar2(20)
    insert into account values (123, 'John Doe');
    insert into account values (124, 'Jane Donaldson');
    insert into account values (125, 'Harold Douglas');
    create table marketer_account (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account values (1001, 123, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('27.09.2009', 'dd.mm.yyyy'));
    insert into marketer_account values (1017, 123, 10987, to_date('28.09.2009', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    insert into marketer_account values (1023, 124, 10541, to_date('03.12.2010', 'dd.mm.yyyy'), to_date('31.12.4712', 'dd.mm.yyyy'));
    create table marketer_account_archive (
        key number
      , AccountId number
      , MktKey number
      , FromDt date
      , ToDate date
    insert into marketer_account_archive values (1015, 124, 10526, to_date('03.08.2008', 'dd.mm.yyyy'), to_date('02.12.2010', 'dd.mm.yyyy'));
    insert into marketer_account_archive values (1033, 125, 10987, to_date('01.01.2011', 'dd.mm.yyyy'), to_date('31.01.2012', 'dd.mm.yyyy'));
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
         , max(FromDt) over(partition by AccountId) max_FromDt
      from marketer_account_archive;
    with
    basedata as (
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account
    union all
    select key, AccountId, MktKey, FromDt, ToDate
      from marketer_account_archive
    basedata_with_max_intervals as (
    select key, AccountId, MktKey, FromDt, ToDate
         , row_number() over(partition by AccountId order by FromDt desc) FromDt_Rank
      from basedata
    filtered_basedata as (
    select key, AccountId, MktKey, FromDt, ToDate from basedata_with_max_intervals where FromDt_Rank = 1
    select a.id
         , a.name
         , b.MktKey
         , b.FromDt
         , b.ToDate
      from account a
      join filtered_basedata b
        on (a.id = b.AccountId)
    ID NAME                     MKTKEY FROMDT     TODATE
    123 John Doe                  10987 28.09.2009 31.12.4712
    124 Jane Donaldson            10541 03.12.2010 31.12.4712
    125 Harold Douglas            10987 01.01.2011 31.01.2012
    If your tables are big it could be necessary to do the filtering (according to your condition) in an early step (the first CTE).
    Regards
    Martin

  • Query help : Query to get values SYSDATE-1 18:00 hrs to SYSDATE 08:00 hrs

    Hi Team
    I want the SQl query to get the data for the following comparison : -
    Order Created is a Date Column , and i want to find out all the values from (SYSDATE-1) 18:00 hours to SYSDATE 08:00 hours
    i.e.
    (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 08:00:00.
    Regards

    Hi, Rohit,
    942281 wrote:
    If i want the data in the below way i.e.
    from (SYSDATE-1) 18:00 hours to SYSDATE 17:59 hours ---> (SYSDATE-1) 18:00:00 < Order.Created < SYSDATE 07:59:00.If you want to include rows from exactly 18:00:00 yesterday (but no earlier), and exclude rows from exatly 08:00:00 today (or later), then use:
    WHERE   ord_dtl.submit_dt  >= TRUNC (SYSDATE) - (6 / 24)
    AND     ord_dtl.submit_dt  <  TRUNC (SYSDATE) + (8 / 24)
    So can i use the below format : -
    ord_dtl.submit_dt BETWEEN trunc(sysdate)-(6/24) and trunc(sysdate)+(7.59/24) . Please suggest . .59 hours is .59 * 60 * 60 = 2124 seconds (or .59 * 60 = 35.4 minutes), so the last time included in the range above is 07:35:24, not 07:59:59.
    If you really, really want to use BETWEEN (which includes both end points), then you could do it with date arithmentic:
    WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - (6 / 24)
                      AND         TRUNC (SYSDATE) + (8 / 24)
                                               - (1 / (24 * 60 * 60))but it would be simpler and less error prone to use INTERVALs, as Karthick suggested earlier:
    WHERE   ord_dtl.submit_dt  BETWEEN  TRUNC (SYSDATE) - INTERVAL '6' HOUR
                      AND         TRUNC (SYSDATE) + INTERVAL '8' HOUR
                                               - INTERVAL '1' SECONDEdited by: Frank Kulash on Apr 17, 2013 9:36 AM
    Edited by: Frank Kulash on Apr 17, 2013 11:56 AM
    Changed "- (8 /24)" to "+ (8 /24)" in first code fragment (after Blushadown, below)

  • Query help, subtract two query parts

    Hi,
    I am beginner of PL/SQL and have a problem I couldn’t solve:
    Table (op_list):
    Item     -     Amount -     Status
    Item1     -     10     -     in
    Item2     -     12     -     in
    Item3     -     7     -     in
    Item1     -     2     -     out
    Item2     -     3     -     out
    Item1     -     1     -     dmg
    Item3     -     3     -     out
    Item1     -     2     -     out
    Item2     -     5     -     out
    Item2     -     2     -     in
    Item3     -     1     -     exp
    Would like to get result of query (subtract amount of 'out/dmg/exp' from 'in' ):
    Item - Amount left
    Item1     -     5
    Item2     -     6
    Item3 -     3
    I wrote code that returns sum of all incoming items and sum all out/dmg/exp items, but couldn’t solve how to subtract one part of querry from another. Or maybe there is a better way. Also worried what happens if there is no 'out/dmg/exp' only 'in'
    select item.name, sum(op_list.item_amount)
    from op_list
    inner join item
    on op_list.item = item.item_id
    where op_list.status = 'in'
    group by item.name
    union
    select item.name, sum(op_list.item_amount)
    from op_list
    inner join item
    on op_list.item = item.item_id
    where op_list.status = 'out'
    or op_list.status = 'dmg'
    or op_list.status = 'exp'
    group by item.name
    Return:
    Item1     -     10      [10 in]
    Item1     -     5     [2+1+2]
    Item2     -     14     [12+2]
    Item3     -     7
    Item3     -     4     [3+1]
    Thanks in advance

    Hi,
    We can also use simple inline views to get what we need.
    select a.item,a.amount-b.amount Balance from
    (select item,sum(amount) Amount from op_list
    where status = 'in'
    group by item) a,
    (select item,sum(amount) Amount from op_list
    where status in ('out','dmg','exp')
    group by item) b
    where
    a.item=b.item
    order by item;
    ITEM       BALANCE
    Item1                      5
    Item2                      6
    Item3                      3Regards,
    Prazy

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • QUERY HELP!!! trying to create a query

    i'm creating a summary report
    i have a table with sale dates
    for example i have a table tab_1 and column saleDate as
    saleDat
    1923
    1936
    1945
    2003
    2005
    saleDate contains years and there are some missing years where no sale
    was made
    My report has to display years starting from earliest year
    so i have to create a query that starts with 1923
    but the problem is that I have to have years that are not in table.
    for example i have to display years 1924 which is not in table
    so the part of report has to look like
    1923 blah blah summary.........
    1924 "
    1925
    1926
    2005
    2006
    upto current year (2006 may not be in the table, but i have to display)
    i just need to know the query that can query all the years starting from
    the ealiest saleDate to current year
    thanks in advance

    Please write the query in the following form:
    SELECT a.year, --- place other columns from your table.
    FROM (SELECT (:start_num + rownum) year
    FROM all_tab_columns
    WHERE :start_num + rownum <= :end_num) a,
    tab_1 b
    WHERE a.year = b.saleDat(+);
    Note:
    1) if your start year and end year are 1923 and 2006. Then input as below:
    :start_num = 1922
    :end_num = 2006
    2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
    3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
    Hope this helps.
    - Saumen.

  • IF statement in Query

    Hi
    I have a query / recordset that  would be looking at 12000 rows in a database and 10 different variables and potential filters chosen by end users.
    Should I put 10 wild card / url Where statements in my recordset query or should I put IF statements in my query.
    ie.
    If URL colname then ",and BetType= "xzz"" .
    Is that the most efficient way to run my queries.
    I will be running about 10 recordsets on my page all looking at these url variables so it will be a busy page.
    If that is the answer can someone please tell me how to insert the if statement - i've tried allsorts but it wont work.
    $colname_Recordset4 = "%";
    if (isset($_GET['colname'])) {
      $colname_Recordset4 = $_GET['colname'];
    mysql_select_db($database_racing_analysis, $racing_analysis);
    $query_Recordset4 = sprintf("SELECT BetType, sum(if(season='2006-2007', Bet, 0)) AS '2006-2007',  sum(if(season='2007-2008', Bet, 0)) AS '2007-2008',  sum(if(season='2008-2009', Bet, 0)) AS '2008-2009' FROM dataextract WHERE BetType Like %s and TrackID = 1 and Distance = 1000 and Class = 1 GROUP BY BetType", GetSQLValueString($colname_Recordset4, "text"));
    $Recordset4 = mysql_query($query_Recordset4, $racing_analysis) or die(mysql_error());
    $row_Recordset4 = mysql_fetch_assoc($Recordset4);
    $totalRows_Recordset4 = mysql_num_rows($Recordset4);
    hope someone can help.
    Simon

    That part of the query cross tabs my data into three columns - not intended to confuse the issue. I'd have the same problem with a basic query.
    So Here is a very basic version:
    I want an IF statement to go around: "WHERE Distance = 1000" and "AND Class = 1"
    That I believe will reduce the effort on the MYSQL Server as it wouldn't be running a bunch of wild card queries and would only run if there is a URL paramter delivered.??
    I just don't get how to put the IF statements in PHP.
    thanks
    $maxRows_Recordset3 = 5;
    $pageNum_Recordset3 = 0;
    if (isset($_GET['pageNum_Recordset3'])) {
      $pageNum_Recordset3 = $_GET['pageNum_Recordset3'];
    $startRow_Recordset3 = $pageNum_Recordset3 * $maxRows_Recordset3;
    mysql_select_db($database_racing_analysis, $racing_analysis);
    $query_Recordset3 = "SELECT * FROM dataextract WHERE Distance = 1000 AND Class = 1";
    $query_limit_Recordset3 = sprintf("%s LIMIT %d, %d", $query_Recordset3, $startRow_Recordset3, $maxRows_Recordset3);
    $Recordset3 = mysql_query($query_limit_Recordset3, $racing_analysis) or die(mysql_error());
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    if (isset($_GET['totalRows_Recordset3'])) {
      $totalRows_Recordset3 = $_GET['totalRows_Recordset3'];
    } else {
      $all_Recordset3 = mysql_query($query_Recordset3);
      $totalRows_Recordset3 = mysql_num_rows($all_Recordset3);
    $totalPages_Recordset3 = ceil($totalRows_Recordset3/$maxRows_Recordset3)-1;

  • IF and ABS condition statement in BEX query designer

    Hi,
    I would like to ask the best way for me to produce an acceptable result from Excel IF and ABS Condition statement.
    The condition statement that I have on my Excel file is
    =IF((A2-B2)>0,ABS(A2-B2),0)
    I'm trying multiple times to reproduce this in BEX Query designer, unfortunately I'm getting a bad result or unacceptable formula.
    Anyone who could help me with my issue?
    Thanks,
    Arnold

    Hi Arnold,
    Thank you,
    Nanda

  • Text value is not getting displayed in Query designer !!

    Dear experts..,
    i have created a new query in query designer using my info provider and then selected one field in default value and then trying to restrict that particular field while selecting the restriction in query designer am getting the exact text value but after generating the report instead of text value , key value is getting displayed....so how can i get text instead of key value??
    please help me friends....
    i have posted in OSS mesage also...i got a reply like...even i didnt understand his reply too...what he is trying to say?
    whether can i get text display or not???
    can any one help me in this regard???
    SAP Reply----
    Hello kumar,
    After another analysis I have to inform you about general concept of
    "compounded characteristics".
    A compounded characteristic bounds two characteristics. The technical
    name is generated by both technical names of the two characteristics
    combined by two underlines "__".
    An individual text is only available for one single combination of both
    characteristics.
    Example:
    =======
    Compounded characteristic "Famous family name" is a combination of
    characteristic "COUNTRY" & "ETHNIC". Technical name: COUNTRY__ETHNIC
    Values for Country: USA, Australia
    Values for Ethnic: Asian, Latino
    Possible value combinations with individual text:
    USA & Asian; text: "Ling"
    USA & Latino; text: "Sanchez"
    Australia & Asian; text: "Chu"
    Australia & Latino; text: "Garcia"
    (Keep in mind the individual text only valid for the specific
    combination.)
    In analogy to the issue that you reported, you want to restrict this
    compounded characteristic. In the window where you select the restrictedvalue (called Selector) you'll see on the left hand side all available
    combinations of the characters with an individual text.
    You select family name "Chu" and drag'n'drop it to the right side.
    Actually you can only restrict the right compounded characteristic. In
    our example you would restrict on characteristic "ETHNIC" with value
    "Asian". (When you switch on technical names this comes more clear). Thetext "Chu" is displayed in the context of Selector because you selected
    value combination Australia & Asian. But in the end it's just a
    placeholder(!) for any combination of characteristic "ETHNIC" and value
    #Asian#; in our example it could be USA & Asian "Ling" or Australia &
    Asian "Chu").
    By leaving the Selector the individual text is gone because now the
    context is lost between the two characteristics. You have just a
    restriction on characteristic "ETHNIC" with value "Asian". An individualtext can't be displayed because the compounded characteristic is not
    specified for this restriction.
    You're right, it is confusing when "loosing" the text of a restriction.
    But accoring to the concepts of the compounded characteristics it
    is a correct behavior.

    Hi anandkumar,
    I belive this issue can be resolved by changing the  Query proprties for the perticular field.
    Kindly check the Field proerties in query designer and ensure that Text is enabled ather than Key.
    __Field property check up:__Go to query designer->click onn the field-> Right hand side in properties click on display tab-> select Text in drop down menu of Display as tab.
    FURTHER CHECK UP: check the master data avaiulability for the perticular info object, if masterdata is not available, do the text data for txt data availability in report level.
    Hope this helps you!!
    Best Regards,
    Maruthi

  • Master data is not getting displayed in the Query Designer

    Hi,
    I have a DSO in which I have an InfoObject called Emp No. in the Data Field.
    The Emp.No is being maintained as master with (Emp Name, Address, Telephone No, DOB) as attributes.
    I have loaded the data in the Emp. No. master. Then tried loading the transaction data in DSO.
    The Emp.No is there in the DSO active data, but in the query designer its not getting displayed.
    Hope its clear.
    Please help.
    Thanks

    Hi,
    I have brought the Emp. No. in the Key Field and also have activate the master data again.
    Yet my Query Designer doesn't have the Emp. No.
    I have done a full load for both Master and Transaction.
    Please advice me what the other alternative.
    Thanks

Maybe you are looking for

  • How do i add multiple Audio files into an Interactive PDF

    I am making a band EPK (Electronic Press Kit) and one one page there are 3 songs the band wants to put in a play and stop feature so the client can hear the music. I have not been able to get the audio files to export in the document in either MP3 or

  • How to add a button in the child node of the Tree Table?

    Hi All, I am having a requirement to create a tree table and it should have a delete button to each child node (screenshot attached). Can anyone provide me a sample for how to implement this. Thanks in Advance Aravindh

  • I have a 2008 13" Mac Book and want to put a solid state drive in it

    I installed Lion firdt and then Clones my hard drive to the solid state drive but it has issues. I tried to do a clesn install on the solid state drive but the install will not complete

  • Go to a position RELATIVE to the current

    Hallo, For the Homepage of my School I have to make a Page-Overview. I use many (this time 20) different, but same sized, images. These should stay 10 sec. and then should come the next one. If you click (on.Press) at the image, the page should be op

  • Query related to .tpz files

    Hi, I am having query related to .tpz files. I am having XI Development server on AIX. My XI Prd server will be on windows NT . <b>Can i transport .tpz file from development server to production server as both the servers are on different platforms.<