Sql query to fetch data based on date conditons

Hi All,
We have to schedule a script that runs at 1:00 AM from Monday to Friday.
The script will run a  sql query  ,that will fetch the data from sql database 2008 based on the below conditions.
Case 1: If date = current Date then retrieve the data of the previous Date.
Case 2: If date = Monday then retrieve the entries of Friday ,Saturday and Sunday.
Please help us on how we can achieve this.
Thanks

Hi,
Are you asking about Patrick's
solution?
If so I highly recommend NOT to use this solution. PLease read LMU92's
and
Visakh16's responses.
Why not to use it?
1. This solution is not deterministic!
A deterministic algorithm is an algorithm which, given a particular input, will always produce the same output. This solution give different values for different setting! It is depending for example on "SET LANGUAGE" value
As mentioned above if you try to use any other languge then English then this query will not work since you will never get the value "Sunday"
2. Moreover! Even if you are using "SET LANGUAGE 'English'" then this
solution depend on "SET DATEFIRST" and only take into consideration that the value can be 1 or 7, using any other value you will get that @weekendDateMod is null!
What can you use?
let's test some value first to get the solution yourself. We know that we don't care about "SET LANGUAGE" since I will not use any language dependency but we need to examine "SET DATEFIRST". Try to change the value from 1 to 7 and check
the value of this query
SET DATEFIRST 1 -- Change this value from 1 to 7!
DECLARE @Sunday DATE = '2014-08-03' -- This is Sunday
DECLARE @Munday DATE = '2014-08-04' -- This is Munday
SELECT DATEPART(DW,@Sunday),DATEPART(DW,@Munday), @@DATEFIRST
Can you see the behavior ?
The results are hidden here (select the text and you will see them)
DATEFIRST___Sunday_______Monday
1___________7___________1
2___________6___________7
3___________5___________6
4___________4___________5
5___________3___________4
6___________2___________3
7___________1___________2
assuming you did the exercise above yourself, then  you can now think now what is the filter that you need...
You can use a filter on those two parameters together using "where DATEPART... and @@DATEFIRST...) or using one combine check. Can you think how?
Notice that this value is always 2 on Monday! Regarding our setting
(DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7
Please Don't Go Down Before YOu Understand!
Now we can go to the solution
* I really hope that you read all and did the small exercise yourself! You can not become a developer by copy answers, and this is the reason that from the start I only gave you tha way and not the final query!
DECLARE @CurrentDate DATE = '2007-08-20' -- This is only for testing since you should use the function GETDATE() instead
DECLARE @MinDateToFilter DATE
SET @MinDateToFilter = CASE
WHEN ((DATEPART(DW,@CurrentDate) + @@DATEFIRST) % 7) = 2 THEN DATEADD(DAY,-4,@CurrentDate)
ELSE DATEADD(DAY,-1,@CurrentDate)
END
SELECT *
FROM sales.salesOrderHeader
WHERE orderDate > @MinDateToFilter
I hope this was useful :-)
[Personal Site] [Blog] [Facebook]

Similar Messages

  • How will write SQL query to fetch data from  each Sub-partition..

    Hi All,
    Anyone does have any idea about How to write SQL query to fetch data from Sub-partition.
    Actually i have one table having composite paritition(Range+list)
    Now if i want to fetch data from main partition(Range) the query will be
    SELECT * FROM emp PARTITION(q1_2005);
    Now i want to fetch data at sub-partition level(List) .But i am not able to get any SQL query for that.
    Pls help me to sort out.
    Thanks in Advance.
    Anwar

    SELECT * FROM emp SUBPARTITION(sp1);

  • SQL query to fetch records  from  26 onwards

    Want to know SQL query to fetch records from 26 onwards.

    See the fifth entry on the FAQ page:
    Re: How to attach a java bean in forms6i

  • SQL query to fetch WIP jobs agains a customer

    Hi All,
    Can anyone please help me with a SQL query to fetch WIP jobs agains a customer.
    Regards,
    Shruti

    If you are using ATO functionality and if you are reserving sales orders to work orders, you can link them as follows
    Using customer name, identify the open sales order headers and lines.
    For each line, query reservations (mtl_reservations) using demand id fields.
    For those reservations where supply = wip job, use the supply id fields and get wip_entity_id.
    Using wip_entity_id, get wip_entity_name(job#) from wip_entities table.
    Once a job is completed, this link is lost.
    Sandeep Gandhi

  • EJB Query Language where condtion based on date

    Hi,
    I am using EJB3 query language. In the table I have a column called requestdate which is in date time format. I have created an entity class.
    I need to select few records using query language(named queries) based on this requestdate matching to the current date. I want to compare only based on Date value (truncating the time). Something like this
    select max(o.req_id) from requests o where o.requestdate = :currentdate
    currentdate is java.sql.Date value formatted to yyyymmdd only.
    How can I do this using query language?
    Please help to me get this done.
    thanka
    Anuradha

    Hi 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

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • Sql query to seperate character and number data in a column

    Hi,
    We have a test table on 10.2.0.4 db as below;
    10:44:34 TEST:WAULT > desc t;
    Name Null? Type
    EMP VARCHAR2(10)
    10:43:18 TEST:WAULT > select * from t;
    EMP
    JOHN
    7281
    TOM
    7852145
    BNPPARIBAS
    9862354
    Mindcraft
    875
    INFINITY
    78998775
    01234
    EMP
    0
    -123
    -856359
    SCOTT
    -657
    16 rows selected.
    The question is; we need to segregate the character data and numerical data in the EMP field, using sql query.
    Plz suggest as to how we can achieve this.
    Also, plz suggest how the use of reqexp can be made in this to achieve the same.
    Thanks,
    Rahul

    >
    Hi,
    EMP
    JOHN
    7281
    TOM
    7852145
    The question is; we need to segregate the character data and numerical data in the EMP field, using sql query.
    Plz suggest as to how we can achieve this.Check out the CAST function
    http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/functions015.htm
    However, I would have to ask why on earth you're doing this - it would, IMHO, be
    much better to redesign your app. It looks like you have an EAV problem
    (AKA MUCK or OTLT) Google Joe Celko and these terms.
    Paul...
    Rahul

  • Command the execute sql query and does not clean up data in Table

    Hi Team
    I have an SP, which writes source and target data to Temp Tables and runs except query to get mismatch details
    I am using Exec command to execute source query that writes data to Temp Table, once I execute query using Exec, data is written and immediately #temp table is cleaned, now I cannot use #temp table for comparition.
    Is there any way to execute sql query in SP without using EXEC and will hold the data in temp table.

    You need to create temp table before EXEC statement and rewrite your dynamic query also as below
    declare @source_Sql nvarchar(1000)
    ,@target_Sql nvarchar(1000)
    create table #TempTable1 (name nvarchar(10))
    create table #TempTable2 (name nvarchar(10))
    set @source_Sql = 'INSERT INTO #TempTable1 SELECT [Name] from Employee'
    set @target_Sql = 'INSERT INTO #TempTable2 SELECT [Name] from Employee2'
    EXEC (@source_Sql)   
    EXEC (@target_Sql)             
    select * from #TempTable1 
     Except 
    select * from #TempTable2

  • Sql query-filter if 1 set of data exists and in the same time 2 set doesnt

    Hi guys,
    I need to write a query where I filter on certain data being present, but in the same time other data from the same table being not present.
    For example:
    ProceduresTable:
    Type 1
    Type 1
    Type 2
    Type 2
    Type 1
    MyTable:
    Name
    OtherFields
    JoiningTable (many to many)
    ProceduresTable_Key
    MyTable_Key
    I need to select all records from MyTable and Procedures for which there are procedures from Type 1 but there are no procedures from Type 2 in the same time.
    So far I've been only able to do that by using subqueries and I think there should be an easier way to do that.
    Here is what I have:
    Select * From MyTable, Procedures, JoiningTable Where JOINING_CONDITIONS AND Type = 1 AND NAME_SOME_COLUMN NOT IN (SELECT NAME_SOME_COLUMN FROM ... WHERE Type = 2 and inner.Name = outer.Name)
    Hope you understand my meta code. I have Oracle 9 db.
    Thanks a lot!

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps if you post a specific example. Include CREATE TABLE and INSERT statements for a little sample data, and also post the results you want from that data.
    if you can use commonly available tables (like those in the scott or hr schemas) to illustrate your proble, then you don't have to post the sample data; just the results.
    For example, I think you're asking something like this:
    "How can I find information about people in the sciott.emp table who are in a department that has at least one CLERK ( that is, a row with job='CLERK') but no SALESMAN? That is, I want these results:
    {code}
    ENAME DEPTNO JOB
    CLARK 10 MANAGER
    KING 10 PRESIDENT
    MILLER 10 CLERK
    JONES 20 MANAGER
    FORD 20 ANALYST
    ADAMS 20 CLERK
    SMITH 20 CLERK
    SCOTT 20 ANALYST
    {code}
    One way is to use CASE expressions instead of WHERE clauses to test for the criteria, then using the reults of the CASE expressions in the WHERE clause.
    For example:
    WITH     got_cnts     AS
         SELECT     ename,     deptno,     job
         ,     COUNT ( CASE
                             WHEN  job = 'CLERK'
                       THEN  1
                         END
                    ) OVER (PARTITION BY deptno)     AS clerk_cnt
         ,     COUNT ( CASE
                             WHEN  job = 'SALESMAN'
                       THEN  1
                         END
                    )     OVER (PARTITION BY deptno)     AS salesman_cnt
         FROM     scott.emp
    SELECT     ename,     deptno,     job
    FROM     got_cnts
    WHERE     clerk_cnt     > 0
    AND     salesman_cnt     = 0
    ;The problem here is that you can't always tell, by looking at any one row, if it should be included or not; in this case, you need to know something about the department as a whole. Analytic functions can look at the department as a whole, but analytic functions are computed after the WHERE clause is applied, so to use the results of the analytic functions in a WHERE clause, we need to do the analytics first, in a sub-query, and the WHERE clause later.
    Sometimes (as in the example above) analytic functions are useful; other times, aggregate functions are more appropriate, depending on the exact requirements.
    Edited by: Frank Kulash on Apr 12, 2010 9:00 AM

  • Restrict Query Data based on Date range and Users

    Hi All,
    I have a few web reports that I need do restrict data based on Users.
    In all the queries i have an infoobject 0CALDAY, and  a User Entry range variable on it. Because of performance issues  I need to restrict the range of dates a User can see. Typically most of users could go to a max date range of 1 month back. But some others would need the ability to see data for much bigger range of dates.
    Pls suggest how should i go about with this. Should I have to enforce this at Variable level(user exit).... but then i might have to maintain a table for the users.. Is there any other way of doing it.
    thanks
    Raj

    Any thoughts ?

  • How to use sql:query/ tag to retrive the system date?

    hi all,
    i want to know if i can use the <sql:query/> tag in jstl to get the database server time. please send me a code snippet to retrive n display the result. i'm new to jstl tags. please help.
    thank you,
    AM

    Check out the first hits: http://www.google.com/search?q=jstl+sql+tutorial+site:sun.com

  • SQL Query to Fetch 500 Rows at once

    Hi,
      Due to performance issue of the SQL query takes lot of time to execute. I tried modifying the code as mentioned below but it is not working to fetch when search is implemented. Actually data is more than 1 Million Records so it takes lot of time to query the data.
    SELECT DISTINCT
    IMV.*,
      nvl(imv.party_name,imv.bill_to_name) "Bill To Name",
      Imv.Ship_To_City "Reseller City",
      Imv.Ship_To_State "Reseller State",
      Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
      Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
      Cl.City "Customer City",
      Cl.State "Customer State",
      EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'COUNTRY') "Customer Country",
      EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'THEATER') "Customer Theater"
    FROM IB_SUPPORT_CONTRACTS_MV IMV,
      customer_products cp,
      customer_locations cl
    WHERE
    UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
    AND CP.LOCATION_ID                     = CL.LOCATION_ID(+)
    AND ROWNUM <= 501
    Please suggest me how to improve the performance of the query.
    Thanks
    Sudhir

    Hi,
    As mentioned already, this condition is really hurting performance:
    UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
    Could you trim and capitalize the serial numbers before storing them?  Do you really need to remember exactly how the serial numbers were entered?  If you really do, then store it in one column, and store UPPER (TRIM (serial_number)) in a different column.  Starting in Oracle 11, this could be a virtual column; in any version (7 or higher), it could be maintained by a trigger.  Failing that, create a function-based index on UPPER (TRIM (serial_number)).

  • SQL query to fetch approximately 9000 rows

    Hi,
    I am using the following SQL query in a java class. Using JDBC to connect to an Oracle database using JRUN app server connection pooling.
    SELECT PT.ACCOUNT_NUMBER,PAYMENT_REF_ID, TO_CHAR (PT.DATE_CREATED, 'MM/DD/YYYY'),
    PT.AMOUNT_PAID, DECODE(STATUS_VALUE,'Cancelled','Canceled',STATUS_VALUE)
    FROM EPAY_PAYMENT_TRANSACTIONS PT, EPAY_STATUS_LOOKUP SL
    WHERE
    PT.CLIENT_NAME = 'someclientname'
    AND TO_CHAR(DATE_PAYMENT_SCHEDULED,'MM/DD/YYYY') = '08/28/2006'
    AND PT.PAYMENT_STATUS = SL.STATUS_CODE
    ORDER BY PT.DATE_CREATED DESC
    EPAY_PAYMENT_TRANSACTIONS is a huge table consisting of thousands of rows. There are 4 indexes defined on this table but not on the columns used in the join condition of the query.
    EPAY_STATUS_LOOKUP is a much smaller table mainly used for lookup consisting of some 100 rows.
    The above query fetches approx 9000 records and takes a very long time to execute. Is there any way it can be optimized or we can change some attributes on the tables involved for speeding up the query?
    Thanks in advance,
    Nisha.

    So the task is to avoid FTS on EPAY_PAYMENT_TRANSACTIONSWell, maybe...
    But I believe that we have yet to hear more details about data distribution, execution plans and so on.
    Because it all depends...
    Consider simple testcase:
    SQL> select * from v$version where rownum = 1;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    SQL> -- Create "small" table
    SQL>
    SQL>  create table build_t as
      2   select rownum x,
      3          rpad('*', 200, '*') padding
      4     from dual
      5  connect by level <= 100;
    Table created.
    SQL> -- Create "large" table - initially, add 9000 rows which satisfy join criteria
    SQL>
    SQL>  create table probe_t as
      2   select mod(rownum - 1, 100) + 1 x,
      3          dbms_random.value y,
      4          rpad('*', 200, '*') padding
      5     from dual
      6  connect by level <= 9000;
    Table created.
    SQL> -- Now, add some extra rows to large table - "thousands of rows"
    SQL>
    SQL>  insert into probe_t
      2   select rownum + 100,
      3          0,
      4          rpad('*', 200, '*') padding
      5     from dual
      6  connect by level <= 100000;
    100000 rows created.
    SQL> exec dbms_stats.gather_table_stats(user, 'BUILD_T')
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.gather_table_stats(user, 'PROBE_T')
    PL/SQL procedure successfully completed.
    SQL> -- Ok, let's measure ...
    SQL>
    SQL> set autot traceonly
    SQL>
    SQL> select a.*, b.*
      2    from build_t a,
      3         probe_t b
      4   where a.x = b.x
      5   order by b.y;
    9000 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1387 Card=109 Bytes=45017)
       1    0   SORT (ORDER BY) (Cost=1387 Card=109 Bytes=45017)
       2    1     HASH JOIN (Cost=1386 Card=109 Bytes=45017)
       3    2       TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
       4    2       TABLE ACCESS (FULL) OF 'PROBE_T' (Cost=1355 Card=109000 Bytes=22781000)
    Statistics
              0  recursive calls
              0  db block gets
           3280  consistent gets
              0  physical reads
              0  redo size
         360756  bytes sent via SQL*Net to client
           7096  bytes received via SQL*Net from client
            601  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
           9000  rows processedOn my server, this query finished in less that second and took 3280 LIO to complete.
    Now, which index did you mean to build? I guess it's and index on join column, isn't it?
    If so - let's build it and measure again:
    SQL> create index idx_probe_t on probe_t(x);
    Index created.
    SQL> select /*+ ORDERED USE_NL(a b) */
      2         a.*, b.*
      3    from build_t a,
      4         probe_t b
      5   where a.x = b.x
      6   order by b.y;
    9000 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=211 Card=109 Bytes=45017)
       1    0   SORT (ORDER BY) (Cost=211 Card=109 Bytes=45017)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'PROBE_T' (Cost=3 Card=1 Bytes=209)
       3    2       NESTED LOOPS (Cost=210 Card=109 Bytes=45017)
       4    3         TABLE ACCESS (FULL) OF 'BUILD_T' (Cost=5 Card=100 Bytes=20400)
       5    3         INDEX (RANGE SCAN) OF 'IDX_PROBE_T' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
              0  recursive calls
              0  db block gets
           9124  consistent gets
             21  physical reads
              0  redo size
         360756  bytes sent via SQL*Net to client
           7096  bytes received via SQL*Net from client
            601  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
           9000  rows processedLook at this - 9124 consistent gets, almost three times larger than in case of hash join.
    Full table scan is not something to be avoided at all cost.
    Indexing - sometimes it is good,
    sometimes it's just useless,
    sometimes it only makes things worse...
    It all depends on underlying data distribution. That's why I asked user527580 to tell us more.
    Kind regards.

  • SQL Query to fetch a specific field in xml

    Hi,
    Below is my sample Xml file.
    <?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
    <methodName>rBatchFile </methodName>
    <params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
         <value>
         D:\test.txt
         </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
         L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </methodName>
    </methodCall>
    I want to query a "value" field based on the "name" field. I tried with the following query which didnt work.
    SELECT a.extract('//value/text()' , 'xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
    FROM ( SELECT t.customerinfo.extract('//member[name="filename"]','xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
    FROM cust_order t ) a;
    Please do provide the SQL query ASAP.

    with tab as (
    select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
    <methodName>rBatchFile </methodName><params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
    <value>
    D:\test.txt
    </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
    L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </params>
    </methodCall>
    ') a from dual
    --end of sample data
    SELECT
      extractvalue(column_value,'/member/name') name,
      extractvalue(column_value,'/member/value') value
    from tab t,xmltable('xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd"','for $i in //member return $i' passing t.a)An example...but i tweaked the xml...check the xml namespace once before executing...
    without adding the namespaces...code will be like...
    with tab as (
    select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall >
    <methodName>rBatchFile </methodName><params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
    <value>
    D:\test.txt
    </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
    L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </params>
    </methodCall>
    ') a from dual
    --end of sample data
    SELECT
      extractvalue(column_value,'/member/name') name,
      extractvalue(column_value,'/member/value') value
    from tab t,xmltable('for $i in //member return $i' passing t.a)Ravi Kumar

  • SQL query to fetch Online Payslip Details

    Hi All,
    First of all "Happy Diwali" to you all and sorry for asking too much. Actually I need to develope an SQL query which will fetch all the details that appears in online payslip(employee self service) including employee details, earning and deduction elements their value, TAX deducted, absence details etc. And the details should match exactally to our online payslip details.
    I am sure many of you have come across this requirement and have developed this already. If you still have that query could you please pass it to me. I know expecting a readymade sql query would be too much and therefore just let me know all the tables I need use for this so that I can start writting query by my own. Actually any help in this regard will be much appreciated.
    P.S. We are still using 11i :-(
    Thank you all once again,
    Avinash

    Hi All,
    Thank you all for your help on this. The forum was really helpful to get answer of my question. I have almost got answer to all my question. Hence marking this "Answered" :-) I have prepared some sql which fetches the information from PAY_ACTION_INFORMATION for Australia legislation and would like to share it with you all so that you can utalize it if needed.
    ------------ For Employee Details ---------------------------------------
    select pai.action_information1 "Employee"
    ,pai.action_information18 "Employer Name"
    ,pai.action_information10 "Employee Number"
    ,pai.action_information19 "Position"
    ,pai.action_information14 "Assignment Number"
    ,pai.action_information17 "Job"
    ,pai.action_information7 "Grade Step"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'EMPLOYEE DETAILS'
    and action_context_id = &action_context_id
    ------------ for IBN Number ----------------------------------------------
    select pai.action_information21 "Employer ABN"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'AU EMPLOYEE DETAILS'
    and action_context_id = &action_context_id
    ------- For Balances ------------------------------------------------------
    select pai.action_information1 "Description"
    ,pai.action_information4 "YTD"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC BALANCES'
    and action_context_id = &action_context_id
    --------- Taxable Earning ------------------------------
    select pai.action_information1 "Description"
    ,pai.action_information9 "Rate"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Taxable Earnings'
    and action_context_id = &action_context_id
    ----------- Pre Tax Deduction -------------
    select pai.action_information1 "Description"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Pre Tax Deductions'
    and action_context_id = &action_context_id
    --------------- Non Taxable Earnings -----------
    select pai.action_information1 "Description"
    ,pai.action_information9 "Rate"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Non Taxable Earnings'
    and action_context_id = &action_context_id
    --------- for Tax Deductions ----------------------
    select pai.action_information1 "Description"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Tax Deductions'
    and action_context_id = &action_context_id
    ---------- Post Tax Deductions -----------------
    select pai.action_information1 "Description"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Post Tax Deductions'
    and action_context_id = &action_context_id
    --------- Employer Superannuation Contributions ----------------------
    select pai.action_information1 "Superannuation Fund Name"
    ,pai.action_information5 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ELEMENTS'
    and action_information4 = 'Employer Superannuation Contributions'
    and action_context_id = &action_context_id
    ----------- Payments -----------------------------
    select pai.action_information18 "Payment Method"
    ,pai.action_information6 "Account Number"
    ,pai.action_information16 "Payment Amount"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'EMPLOYEE NET PAY DISTRIBUTION'
    and action_context_id = &action_context_id
    ------------- Other Pay Advice Information ------------
    select pai.action_information14 "Description"
    ,pai.action_information6 "Value"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'EMPLOYEE OTHER INFORMATION'
    and action_information2 = 'ELEMENT'
    and action_context_id = &action_context_id
    -------------------- Other Balance Information -----------
    select pai.action_information14 "Description"
    ,pai.action_information6 "Value"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'EMPLOYEE OTHER INFORMATION'
    and action_information2 = 'BALANCE'
    and action_context_id = &action_context_id
    ------------------- Pay Period and Salary ------------
    select pai.action_information28 "Annual Salary"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'EMPLOYEE DETAILS'
    --and action_information2 = 'BALANCE'
    and action_context_id = &action_context_id
    --------------- Annual Leave Information ------------
    select pai.action_information1 "Name"
    ,decode(pai.action_information5,'D','Day','H','Hours') "Unit"
    ,pai.action_information4 "Balance"
    from apps.pay_action_information pai
    where 1 = 1
    and pai.action_information_category = 'APAC ACCRUALS'
    and action_context_id = &action_context_id
    ----------- Message to Employee -----------
    select pai.action_information6 "Message to Employee"
    from apps.pay_action_information pai
    where 1 = 1
    and action_information_category = 'EMPLOYEE OTHER INFORMATION'
    and action_information2 = 'MESG'
    and action_context_id = &action_context_id
    ---------------- Leave Taken -------------
    select pai.action_information2 "Name"
    ,pai.action_information4 "Start Date"
    ,pai.action_information5 "End Date"
    ,pai.action_information6 "Amount Taken"
    ,pai.action_information8 "This Pay"
    from apps.pay_action_information pai
    where 1 = 1
    and action_information_category = 'APAC ABSENCES'
    and action_context_id = &action_context_id
    Thanks,
    Avinash

Maybe you are looking for

  • ITunes won't open after installing update.

    After installing the latest itunes update, itunes won't open at all. I click on it and it just won't open. I tried uninstalling and reinstalling and it still doesn't work.

  • Is it possible that Verizon could have screwed things up more than this?

    I contacted Verizon 10 days ago about internet and cell phone service the person I spoke with told me that Verizon did not offer internet in Illinois and I should call something called Frontier Communications I should have taken this as a sign that I

  • How to solve page flickering in a jsp page for chat

    Hi, I'm trying to build a very simple chat application. I'm using JSP as the frontend. The problem is that when I want to refresh the messages typed and list of users currently logged in, the page is refreshing using html refresh tag. The result is v

  • Unable to assign User groups in Enterprise Portal

    Hi, We are using EP 7.0 with MS SQL on Windows 2003 Server. Recently we have changed the UME to IDES EHP4 System. We can able to create users in the backend system and can read but when we try to assign any groups to the user we are getting the follo

  • Stage/Timeline extremely slow under Mountain Lion

    Hello everyone, I'm having this issue with Flash CS6 on OSX Mountain Lion. Almost every action in the program causes it to slow down considerably. Things such as selecting/moving anything something on the stage, selecting something in the liberary pa