Query for a Value Set

Is there any way to get one record for each of orgs? I would like to use this query in a value set but I can put the word distinct in a value set SQL statement. Any Ideas?
SELECT
haou.NAME ORGANIZATION_NAME
FROM
hr.per_all_assignments_f paaf,
hr_all_organization_units haou
WHERE haou.Organization_id = paaf.Organization_id
AND paaf.primary_flag = 'Y'
AND paaf.assignment_type = 'E'
AND sysdate BETWEEN paaf.effective_start_date AND paaf.effective_end_date
order by 1

Found it...
select name from hr_all_organization_units b
where organization_id in (select organization_id from per_all_assignments_f a
where a.organization_id = b.organization_id )
order by 1

Similar Messages

  • Query to get value sets associated with its descriptive flexfield

    Hi All,
    Here i have a issue
    I am trying to get Value sets associated with its descriptive flex field of Receivable application and
    also if i want this for particular responsibility i.e., GW RBC Receivable Super User.
    I hope u got it.
    Please suggest me some query to get this.
    This is very important for me.

    Hi, I think your question should be addressed to the OEBS experts

  • Execute a query for each value returned by subquery

    Hy, I have a query and a subquery(both of them are selects) and I want the outer query to be executed for each value returned by the subquery but the outer query has to return only one result.
    For example, the following query is right for what I want?:
    the following query finds out which authors live in the same city by looking at the postal code:
    select au_fname, au_lname, city
    from authors
    where city = all
    (select city
    from authors
    where postalcode like "946%")
    I undertand the sentence "select au_fname, au_lname, city from authors where city=" will be executed for each value returned by "select city from authors where postalcode like "946%"". Is this right?
    Thanks

    Hi,
    user13162080 wrote:
    Hy, I have a query and a subquery(both of them are selects) and I want the outer query to be executed for each value returned by the subquery but the outer query has to return only one result. Sorry, I don't understand what you want. What if several rows in the table meet all the criteria? Do you only want some kind of summary of all of them?
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
    For example, the following query is right for what I want?:
    the following query finds out which authors live in the same city by looking at the postal code:
    select au_fname, au_lname, city
    from authors
    where city = all
    (select city
    from authors
    where postalcode like "946%")As I said earlier, I don't know what you want , but whatever it is, the query above is probably not the right way to get it.
    Perhaps you meant "IN" instead of "= ALL", like this:
    SELECT  au_fname, au_lname, city
    FROM      authors
    WHERE      city     IN          -- ***NOT***  = all
              (   SELECT  city
                  FROM    authors
                  WHERE   postalcode LIKE "946%"
    I undertand the sentence "select au_fname, au_lname, city from authors where city=" will be executed for each value returned by "select city from authors where postalcode like "946%"". Is this right?No; the main query will be executed once, and the sub-query will be executed once. The rows in the main query will be compared to the results of the sub-query, to see if they will be included in the result set or not. This goes both for the original query you posted, and the modified version I posted.
    InoL wrote:
    Maybe I don't understand exactly what you want, or you gave a bad example. But your example is simply:
    select au_fname, au_lname, city
    from authors
    where postalcode like '946%'
    No; consider this data:
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Virgil',     'Oakland',     '94601');
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Steinbeck',     'Oakland',     NULL);
    INSERT INTO authors (au_lname, city, postalcode) VALUES ('Grass',     'Emeryville',     '94608');What OP posted would return no rows, because nobody is in both 'Oakland' and 'Emeryville'.
    What you posted would return 'Virgil' and 'Grass'.
    What I posted would reutn all 3 rows, including Steinbeck, whose city is known to be related to a '946%' postalcode, even though his own postalcode is missing.
    Edited by: Frank Kulash on Feb 9, 2011 1:06 PM

  • SQL Query for mapping a set of batches to a class rooms group

    Hi All,
    I am using Oracle 11g Release 2 database.
    I have the following data set:
    ClassRooms
    ClassId ClassName                    Capacity     Group
    1 Babbage/Software Engg Lab          24          1
    2     Basement - PG Block               63          1
    3     Classroom 1                    56          1
    4     Classroom 10                    24          1
    5     Classroom 11                    24          1
    6     Classroom 12                    35          1
    7     Classroom 13                    42          1
    8     Classroom 14                    42          1
    9     Classroom 15                    42          1
    10     Classroom 2                    35          1
    11     Classroom 3                    35          1
    12     Classroom 4                     35          1
    13     Classroom 5                    35          1
    14     Classroom 6                    25          1
    15     Classroom 7                    25          1
    16     Classroom 8                    24          1
    17     Classroom 9                    24          1
    18     Control Sys Lab                    24          1
    19     Dig & Embd Sys Lab               20          1
    20     DSP & Comm Lab                    20          1
    21     Electromechanical System Lab     28          1
    22     Farabi/Web Tech Lab               36          1
    23     Gen Purpose Lab                    40          1
    24     Shirazi/DB Tech Lab               36          1
    25     Adv Elect Lab                    30          2
    26     Classroom 16                    42          2
    27     Classroom 17                    49          2
    28     Classroom 18                    56          2
    29     Classroom 19                    42          2
    30     Classroom 20                    49          2
    31     Classroom 21                    35          3
    32     Classroom 22                    35          3
    33     MDA Lab                         20          3
    DegreeBatches
    BatchId      BatchName Strength
    1          BIT-11          79          
    2          BIT-12          28          
    3          BS(CS)-1          35          
    4          BS(CS)-2          78          
    5          BE(SE)-1          69          
    6          BE(SE)-2          84          
    7          BE(SE)-3          64          
    8          BICSE-7          84          
    9          BICSE-8          43          
    10          BEE-1          112          
    11          BEE-2          151          
    12          BEE-3          157          
    13          BEE-4          157          
    I want to map a degree batch combination to a class rooms group in such away that they fully utilize maximum capacity of the class rooms within a group (Ideal case) or as close to it as possible. Can it be done with a SQL query?
    Any response will be highly appreciated.
    SQL Scripts to generate the required tables and populate data is below:
    CREATE TABLE ClassRooms (ClassId NUMBER, ClassName     VARCHAR2(50), Capacity NUMBER, Group NUMBER);
    INSERT INTO ClassRooms VALUES(1,'Babbage/Software Engg Lab',24,1);
    INSERT INTO ClassRooms VALUES(2,'Basement - PG Block',63,1);
    INSERT INTO ClassRooms VALUES(3,'Classroom 1',56,1);
    INSERT INTO ClassRooms VALUES(4,'Classroom 10',24,1);
    INSERT INTO ClassRooms VALUES(5,'Classroom 11',24,1);
    INSERT INTO ClassRooms VALUES(6,'Classroom 12',35,1);
    INSERT INTO ClassRooms VALUES(7,'Classroom 13',42,1);
    INSERT INTO ClassRooms VALUES(8,'Classroom 14',42,1);
    INSERT INTO ClassRooms VALUES(9,'Classroom 15',42,1);
    INSERT INTO ClassRooms VALUES(10,'Classroom 2',35,1);
    INSERT INTO ClassRooms VALUES(11,'Classroom 3',35,1);
    INSERT INTO ClassRooms VALUES(12,'Classroom 4',35,1);
    INSERT INTO ClassRooms VALUES(13,'Classroom 5',35,1);
    INSERT INTO ClassRooms VALUES(14,'Classroom 6',25,1);
    INSERT INTO ClassRooms VALUES(15,'Classroom 7',25,1);
    INSERT INTO ClassRooms VALUES(16,'Classroom 8',24,1);
    INSERT INTO ClassRooms VALUES(17,'Classroom 9',24,1);
    INSERT INTO ClassRooms VALUES(18,'Control Sys Lab',24,1);
    INSERT INTO ClassRooms VALUES(19,'Dig & Embd Sys Lab',20,1);
    INSERT INTO ClassRooms VALUES(20,'DSP & Comm Lab',20,1);
    INSERT INTO ClassRooms VALUES(21,'Electromechanical System Lab',28,1);
    INSERT INTO ClassRooms VALUES(22,'Farabi/Web Tech Lab',36,1);
    INSERT INTO ClassRooms VALUES(23,'Gen Purpose Lab',40,1);
    INSERT INTO ClassRooms VALUES(24,'Shirazi/DB Tech Lab',36,1);
    INSERT INTO ClassRooms VALUES(25,'Adv Elect Lab',30,2);
    INSERT INTO ClassRooms VALUES(26,'Classroom 16',42,2);
    INSERT INTO ClassRooms VALUES(27,'Classroom 17',49,2);
    INSERT INTO ClassRooms VALUES(28,'Classroom 18',56,2);
    INSERT INTO ClassRooms VALUES(29,'Classroom 19',42,2);
    INSERT INTO ClassRooms VALUES(30,'Classroom 20',49,2);
    INSERT INTO ClassRooms VALUES(31,'Classroom 21',35,3);
    INSERT INTO ClassRooms VALUES(32,'Classroom 22',35,3);
    INSERT INTO ClassRooms VALUES(33,'MDA Lab',20,3);
    CREATE TABLE DegreeBatches (BatchId NUMBER, BatchName VARCHAR2(50), Strength NUMBER);
    INSERT INTO DegreeBatches VALUES(1,'BIT-11',79);          
    INSERT INTO DegreeBatches VALUES(2,'BIT-12',28);          
    INSERT INTO DegreeBatches VALUES(3,'BS(CS)-1',35);          
    INSERT INTO DegreeBatches VALUES(4,'BS(CS)-2',78);          
    INSERT INTO DegreeBatches VALUES(5,'BE(SE)-1',69);          
    INSERT INTO DegreeBatches VALUES(6,'BE(SE)-2',84);          
    INSERT INTO DegreeBatches VALUES(7,'BE(SE)-3',64);          
    INSERT INTO DegreeBatches VALUES(8,'BICSE-7',84);          
    INSERT INTO DegreeBatches VALUES(9,'BICSE-8',43);          
    INSERT INTO DegreeBatches VALUES(10,'BEE-1',112);          
    INSERT INTO DegreeBatches VALUES(11,'BEE-2',151);     
    INSERT INTO DegreeBatches VALUES(12,'BEE-3',157);     
    INSERT INTO DegreeBatches VALUES(13,'BEE-4',157);     
    Best Regards
    Bilal
    Edited by: Bilal on 27-Dec-2012 09:52
    Edited by: Bilal on 27-Dec-2012 10:07

    Bilal, thanks for the nice problem! Another possibility for duplicate checking is to write a small PL/SQL function returning 1 if a duplicate id is found, then equate it to 0: 'Duplicate_Token_Found (p_str_main VARCHAR2, p_str_trial VARCHAR2) RETURN NUMBER'. This would parse the second string and might use p_str_main LIKE '%,' || l_id || ',%' for each id. Anyway the full query (without that) is given below:
    Solution with names
    SQL> WITH rsf_itm (con_id, max_weight, nxt_id, lev, tot_weight, tot_profit, path, root_id, lev_1_id) AS (
      2  SELECT c.id,
      3         c.max_weight,
      4         i.id,
      5         0,
      6         i.item_weight,
      7         i.item_profit,
      8         ',' || i.id || ',',
      9         i.id,
    10         0
    11    FROM items i
    12   CROSS JOIN containers c
    13   UNION ALL
    14  SELECT r.con_id,
    15         r.max_weight,
    16         i.id,
    17         r.lev + 1,
    18         r.tot_weight + i.item_weight,
    19         r.tot_profit + i.item_profit,
    20         r.path || i.id || ',',
    21         r.root_id,
    22         CASE WHEN r.lev = 0 THEN i.id ELSE r.nxt_id END
    23    FROM rsf_itm r
    24    JOIN items i
    25      ON i.id > r.nxt_id
    26     AND r.tot_weight + i.item_weight <= r.max_weight
    27   ORDER BY 1, 2
    28  ) SEARCH DEPTH FIRST BY nxt_id SET line_no
    29  , rsf_con (nxt_con_id, nxt_line_no, con_path, itm_path, tot_weight, tot_profit, lev) AS (
    30  SELECT con_id,
    31         line_no,
    32         To_Char(con_id),
    33         ':' || con_id || '-' || (lev + 1) || ':' || path,
    34         tot_weight,
    35         tot_profit,
    36         0
    37    FROM rsf_itm
    38   UNION ALL
    39  SELECT r_i.con_id,
    40         r_i.line_no,
    41         r_c.con_path || ',' || r_i.con_id,
    42         r_c.itm_path ||  ':' || r_i.con_id || '-' || (r_i.lev + 1) || ':' || r_i.path,
    43         r_c.tot_weight + r_i.tot_weight,
    44         r_c.tot_profit + r_i.tot_profit,
    45         r_c.lev + 1
    46    FROM rsf_con r_c
    47    JOIN rsf_itm r_i
    48      ON r_i.con_id > r_c.nxt_con_id
    49   WHERE r_c.itm_path NOT LIKE '%,' || r_i.root_id || ',%'
    50     AND r_c.itm_path NOT LIKE '%,' || r_i.lev_1_id || ',%'
    51     AND r_c.itm_path NOT LIKE '%,' || r_i.nxt_id || ',%'
    52  )
    53  , paths_ranked AS (
    54  SELECT itm_path || ':' itm_path, tot_weight, tot_profit, lev + 1 n_cons,
    55         Rank () OVER (ORDER BY tot_profit DESC) rnk,
    56         Row_Number () OVER (ORDER BY tot_profit DESC) sol_id
    57    FROM rsf_con
    58  ), best_paths AS (
    59  SELECT itm_path, tot_weight, tot_profit, n_cons, sol_id
    60    FROM paths_ranked
    61   WHERE rnk = 1
    62  ), row_gen AS (
    63  SELECT LEVEL lev
    64    FROM DUAL
    65  CONNECT BY LEVEL <= (SELECT Count(*) FROM items)
    66  ), con_v AS (
    67  SELECT  b.itm_path, r.lev con_ind, b.sol_id, b.tot_weight, b.tot_profit,
    68          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev - 1) + 1,
    69            Instr (b.itm_path, ':', 1, 2*r.lev) - Instr (b.itm_path, ':', 1, 2*r.lev - 1) - 1)
    70             con_nit_id,
    71          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev) + 1,
    72            Instr (b.itm_path, ':', 1, 2*r.lev + 1) - Instr (b.itm_path, ':', 1, 2*r.lev) - 1)
    73             itm_str
    74    FROM best_paths b
    75    JOIN row_gen r
    76      ON r.lev <= b.n_cons
    77  ), con_split AS (
    78  SELECT itm_path, con_ind, sol_id, tot_weight, tot_profit,
    79         Substr (con_nit_id, 1, Instr (con_nit_id, '-', 1) - 1) con_id,
    80         Substr (con_nit_id, Instr (con_nit_id, '-', 1) + 1) n_items,
    81         itm_str
    82    FROM con_v
    83  ), itm_v AS (
    84  SELECT  c.itm_path, c.con_ind, c.sol_id, c.con_id, c.tot_weight, c.tot_profit,
    85          Substr (c.itm_str, Instr (c.itm_str, ',', 1, r.lev) + 1,
    86            Instr (c.itm_str, ',', 1, r.lev + 1) - Instr (c.itm_str, ',', 1, r.lev) - 1)
    87             itm_id
    88    FROM con_split c
    89    JOIN row_gen r
    90      ON r.lev <= c.n_items
    91  )
    92  SELECT v.sol_id,
    93         v.tot_weight s_wt, v.tot_profit s_pr, c.id c_id, c.name c_name, c.max_weight m_wt,
    94         Sum (i.item_weight) OVER (PARTITION BY v.sol_id, c.id) c_wt,
    95         i.id i_id, i.name i_name, i.item_weight i_wt, i.item_profit i_pr
    96    FROM itm_v v
    97    JOIN containers c
    98      ON c.id = To_Number (v.con_id)
    99    JOIN items i
    100      ON i.id = To_Number (v.itm_id)
    101   ORDER BY sol_id, con_id, itm_id
    102  /
        SOL_ID S_WT S_PR  C_ID C_NAME          M_WT C_WT  I_ID I_NAME     I_WT I_PR
             1  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             2  255  255     1 SEECS UG Block   100   95     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             3  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             4  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             5  255  255     1 SEECS UG Block   100   95     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             6  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             7  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             8  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             9  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            10  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            11  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            12  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            13  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            14  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
    98 rows selected.
    Elapsed: 00:00:01.42Edited by: BrendanP on 20-Jan-2013 11:25
    I found the regex needed to deduplicate:
    AND RegExp_Instr (r_c.itm_path || r_i.path, ',(\d+),.*?,\1,') = 0

  • SQL Query for take values on excle sheet

     i have the query `select EmpId,AttenDate,status from dbo.Attendance`
    it will give me this
    1500011 2014-09-01 00:00:00.000
    A
    1500011 2014-09-02 00:00:00.000
    A
    1500011 2014-09-03 00:00:00.000
    A
    1500011 2014-09-04 00:00:00.000
    A
    1500011 2014-09-05 00:00:00.000
    A
    1500011 2014-09-06 00:00:00.000
    P
    1500011 2014-09-07 00:00:00.000
    A
    upto   2014-09-31  00:00:00.000
    A
    68 2014-08-01 00:00:00.000
    A
    68 2014-08-02 00:00:00.000
    P
    68 2014-08-03 00:00:00.000
    A
    68  2014-09-07 00:00:00.000 A
    upto   2014-09-31  00:00:00.000
    A
    Now i want to print it into the excel sheet 
    with is format
    Empid 1
    2 3
    4 5
    6 7
    8 upto 31
    1500011 A   A A
    A A
    P A 
    A upto A
    68     A
    A P
    ....................upto A
    Please suggest me??

     
    Hi SachinDholess,
    Based on my understanding, you want to merge the attendance records for each EmpID into one row as below snapshot rather than in rows, right?
    According to your description, I created and populate the attendance records of September for EmpID
    1500011 and records of August and September for EmpID 68
    to simulate your scenario. In this scenario, the Stored Procedure
    procGetEmpAtt would help you to get the data like above snapshot during a given period. Please see the below code.
    USE TestDB;
    IF OBJECT_ID('dbo.Attendance') IS NOT NULL
    DROP TABLE dbo.Attendance;
    GO
    CREATE TABLE Attendance
    EmpID INT,
    AttenDate DATETIME,
    [status] VARCHAR(99)
    GO
    --Create and Populate the Nums Auxiliary Table
    SET NOCOUNT ON;
    SET ROWCOUNT 0;
    IF OBJECT_ID('dbo.Nums', 'U') IS NOT NULL
    DROP TABLE dbo.Nums;
    CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY);
    DECLARE @max AS INT, @rc AS INT;
    SET @max = 1000;
    SET @rc = 1;
    INSERT INTO dbo.Nums(n) VALUES(1);
    WHILE @rc * 2 <= @max
    BEGIN
    INSERT INTO dbo.Nums(n) SELECT n + @rc FROM dbo.Nums;
    SET @rc = @rc * 2;
    END
    INSERT INTO dbo.Nums(n)
    SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max;
    GO
    --Insert records of September for EmpID 1500011
    INSERT INTO Attendance VALUES(1500011,'2014-09-01 00:00:00.000', 'A');
    INSERT INTO Attendance
    SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<30
    WHERE EMPID=1500011;
    --Insert records of September and August for EmpID 68
    INSERT INTO Attendance VALUES(68,'2014-08-01 00:00:00.000', 'A');
    INSERT INTO Attendance
    SELECT EmpID, DATEADD(DAY,n,AttenDate), [status] FROM Attendance join nums ON nums.n<61
    WHERE EMPID=68;
    DROP TABLE dbo.Nums;
    IF (OBJECT_ID('procGetEmpAtt', 'P') IS NOT NULL)
    DROP PROC procGetEmpAtt
    GO
    CREATE PROC procGetEmpAtt(@startDT DATETIME, @endDT DATETIME)
    AS
    DECLARE @DynamicPivotQuery AS NVARCHAR(MAX);
    DECLARE @ColumnName AS NVARCHAR(MAX);
    DECLARE @Columns AS NVARCHAR(MAX);
    --Get distinct values of the PIVOT Column
    SELECT @ColumnName= ISNULL(@ColumnName + ',','')+ 'ISNULL('+QUOTENAME(dt)+',''Not Recored'') AS '+QUOTENAME(dt),
    @Columns=ISNULL(@Columns + ',','')+QUOTENAME(dt)
    FROM (SELECT DISTINCT CONVERT(varchar(12) , AttenDate, 112 ) as dt FROM Attendance WHERE AttenDate BETWEEN @startDT AND @endDT ) AS A ;
    --Prepare the dynamic PIVOT query
    SET @DynamicPivotQuery =
    N'SELECT EmpID, ' + @ColumnName + '
    FROM Attendance
    PIVOT(MAX([status])
    FOR AttenDate IN (' + @Columns + ')) AS PVTTable ORDER BY EmpID DESC' ;
    --Execute the dynamic Pivot Query
    EXEC sp_executesql @DynamicPivotQuery ;
    GO
    Test example
    SET NOCOUNT ON;
    SET ROWCOUNT 0;
    EXEC procGetEmpAtt
    @startDT='2014-08-29',
    @endDT='2014-09-15'
    The key in this  Stored Procedure is the dynamic Pivot statement, click
    here for more details.
    By the way, I didn’t quite get your point until I copied your description into a Word document. Kindly mind the format of the description you post, a better  formatted one would lead to a much quicker response.
    If you have any question, feel free to let me know.
    Best Regards,
    Eric Zhang

  • SQL query for updating values in same cell of a table

    Hi All,
    I'm stuck with a problem and it stands as follows:
    Table name: Track
    Part1  Part2  Part3
    NULL   NULL   NULL
    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    1,2,3    5          SUBM2
    Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
    Please advise how this could be achieved?
    Kind regards,
    Aniruddha Jagdale

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • SQL Query for max values!!

    Hi to all,
    I have four tables
    Tbl_one
    Tbl_two
    Tbl_three
    Tbl_four
    the relation between these tables is
    Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    I want a query like this
    Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
    from Tbl_one,Tbl_two,Tbl_three,Tbl_four
    where Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    and tbl_three.test_date in (select max(test_date) from tbl_three)
    and tbl_four.order_date in select(max(order_date from tbl_for)
    and max(test_date)> Max(order_date)
    any way it is possible?
    the real problem is there are multiple test_dates and
    multiple order_date for same seq in tbl_one.seq.
    eg: -
    name (indian) which has three or more test_date and each test_date have more than one order_date
    indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
    india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
    india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
    japan has the same situation and so on
    what i wanted from the query is
    max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
    ans: -
    name
    india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
    etc. etc . etc.
    thanks!!
    Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:57 AM

    Please use tags either side of code / data (to preserve the formatting and spacing).
    I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
    Could you please be clearer in your input/output samples and explain more about how to generate the output?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query for multiple value search

    Hi
    I got struck when I try to construct SQL query to fetch multiple values in WHERE clause.
    SELECT columnName from someTable
    WHERE someValue = {here is the problem, I have multiple values here which I get from some array}
    Is there any way I can put multiple values to where clause?

    here we go
    this????
    SQL> var LIST varchar2(200)
    SQL> EXEC :LIST := '10,20';
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL>  SELECT items.EXTRACT('/l/text()').getStringVal() item
      2   FROM TABLE(XMLSEQUENCE(
      3   EXTRACT(XMLTYPE('<all><l>'||
      4   REPLACE(:LIST,',','</l><l>')||'</l></all>')
      5  ,'/all/l'))) items;
    ITEM
    10
    20
    Elapsed: 00:00:00.04
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT empno,
      2         ename
      3    FROM emp
      4   WHERE dno IN (SELECT items.EXTRACT ('/l/text()').getStringVal () item
      5                   FROM TABLE (XMLSEQUENCE (EXTRACT
      6*                   (XMLTYPE ('<all><l>' || REPLACE (:LIST, ',', '</l><l>') || '</l></all>'), '/all/l') ) )
    SQL> /
         EMPNO ENAME
          7934 MILLER
          7839 KING
          7782 CLARK
          7902 FORD
          7876 ADAMS
          7788 SCOTT
          7566 JONES
          7369 SMITH
    8 rows selected.

  • Query for a value result when no rows found

    Kindly help me out when I use following query it return no record but I want 0 against this query how plz let me know
    select b.accode,decode(sum(b.debit),null,0,sum(b.debit)) op_dr,
    decode(sum(b.credit),null,0,sum(b.credit)) op_cr,
    c.actitle
    from v_mast a, v_det b, chart c
    where a.v_type=b.v_type
    and a.vouchno=b.vouchno
    and b.accode=c.accode
    and a.VOID='F'
    and a.posted_by is not null
    and a.v_date between '01-JAN-06' and '31-JAN-06'
    and b.accode in (select accode from account where open='T')
    and b.accode in (select accode from chart)
    and a.v_type in ('RN','PV','CV','RV','JV')
    and b.accode = '3050571'
    group by b.accode,c.actitle
    order by b.accode
    Result is : No rows found but is there any possibilities that it will give me following result
    Accode op_dr op_cr
    3050571 0 0

    Why not respond to the earlier threads ?
    Query
    and
    0 when no records found
    Regards,
    Rob.
    Message was edited by:
    Rob van Wijk
    PS: Of course you could do a
    <your query> union all select 3050571,0,0,null from dual
    It answers the question, but I doubt that this is what you want.

  • Value Set Discrepancy

    Hi,
    I entered few records to the table FND_FLEX_VALUES for a specific flex_value_set_id.But wheni query for the value set from the front end i cant find those values.
    However when i try to create the same record from front end i get an error message that the value already exists.
    Not sure what is happening and why i am unable to see the values from front end.
    The value set is an independent value set.
    Please help.
    Thanks,
    Ramendra.

    When you enter value from front end in Independent value set Insertion happens in two tables
    1)FND_FLEX_VALUES
    2)FND_FLEX_VALUES_TL
    Here you have manually Inserted in FND_FLEX_VALUES but not in FND_FLEX_VALUES_TL.
    Now 1) you can't see those manually inserted records in front end is because in form records are displayed from View "FND_FLEX_VALUES_VL" which is
    created on above tables.
    2) you are getting error while you insert from front end because in table FND_FLEX_VALUES records are already inserted by you manually.
    You should not have done manual Insertion in just FND_FLEX_VALUES because there is more more table "FND_FLEX_VALUES_TL" where insertion happens.
    API fnd_flex_loader_apis.up_value_set_value can be used instead of mannual Insertion.
    Sunil
    Edited by: Mendiratta Sunil on 26 Feb, 2009 1:18 PM

  • Can't find value set in values screen of flex field

    Hi,
    I want to see values associated with a value set. This valueset is for one of the segment of Position Flex field of HRMS.
    When I go to Application>FlexField>Key>Values and query for the value set, It doesn't appear in the list of value sets. I am unable to find any value set for any segment. Both the value sets are table based.
    Can anyone tell me why I can't see them?
    Abdul Wahid

    Mark,
    You did not say whether you are using Frame 8 or not, but I use Frame 7.2 and have cross-reference elements in my documents; however, they are named XReference. I have no trouble finding them...an element is an element.
    Check to be sure your EDD includes elements named xref and that when the insertion point is inside some text that the element catalog shows that xref elements are allowed.
    If your EDD does not include xref elements or elements that serve as cross-references but are named differently, then Find will not be able to find them as elements. If you insert your cross-references NOT as elements, then again Find will not find them as elements. You must have an element that you use for cross-references. If so, Find should work.
    Van

  • How to create a value sets for concurrent program?

    Hi Friends,
    I am creating a concurrent program with a parameter period...
    In the value set for the parameter period, I am using the following query :
    ---where application_id = 101
    and set_of_books_id = :$PROFILES$.gl_set_of_bks_id
    and closing_status IN ( 'O', 'F', 'C')
    order by period_year, period_num' ----
    In my cursor, i have a condition 'where set_of_books_id = ' ---
    How can I pass the above set of books id into the cursor ?? it is not working when I am defining another parameter as Book and passing that value to the cursor....
    I need that period parameter to return all the periods for the set of books where we are running the concurrent request from...I also need to get the set of books id for my cursor...
    Hope I am making sense...All that I am trying is to have period parameter and also a SOB id in cursor condition...
    Rgds,

    Hi Vamsi /Nitin,
    Let me explain the whole thing now.....
    My plsql procedure is ......
    CREATE OR REPLACE procedure GL_INT(
         perrbuff     out varchar2,
         pretcode     out varchar2,
    pbook          in varchar2,
    pperiod          in varchar2
         ) is
    cursor cur1 (p_sdate in date, p_edate in date )is
    select distinct group_id groupid,
    user_je_source_name source
    from gl_interface
         where accounting_date >= p_sdate
    and accounting_date <= p_edate
    and set_of_books_id = pbook;
    cursor cur2 is
    select distinct start_date sdate,
         end_date edate, period_name period
    from gl_period_statuses
    where      period_name = pperiod
         and set_of_books_id = pbook
         and application_id = 101;
    i               cur1%rowtype;
    j               cur2%rowtype;
    begin
    open cur2;
                   fnd_file.put_line(fnd_file.output,'PERIOD'||'----'||'GROUPID'||
                                       '----'|| 'SOURCE');
              loop
                   fetch cur2 into J;
    exit when cur2%notfound;
                   open cur1(J.sdate,J.edate);
                   loop
              fetch cur1 into I;
                        exit when cur1%notfound;
              fnd_file.put_line(fnd_file.output, J.period||'----'||I.groupid||'----'||
                                  I.source);
                   end loop;
              end loop;
         Close cur1;
    close cur2;
    Exception when others then dbms_output.put_line(SQLERRM);     
    end;
    ==================================================================================================
    For SOB value set, I have passed the default value as vamsi suggested ($profiles$.gl_set_of_bks_id)....
    For period value set, I have entered query as ..where application_id = 101
    and set_of_books_id = :$PROFILES$.gl_set_of_bks_id
    and closing_status IN ( 'O', 'F', 'C')
    order by period_year, period_num...................
    It still doesn't work....I don't know how to derive those Periods based on the SOBs and at the same time pass SOB id into the cursors...
    Please help...
    Rgds,
    Murali

  • Using Broadcaster to run a query for sequential Variable Values

    Hi SDN Community
    I came across a powerpoint slide regarding broadcasting which i hope to use in one of our reports.
    We are on SAP BW 35.
    Broadcaster has been used
    Your opinion would be greatly valued in regards to the direction i should proceed for our particular purpose.
    We basically have a report which is a web report.  This contains much html and javascript enhancements.
    But it essentially has queries with a series of variables.
    The customer would like the Queries to be cached for each variable value for performance reasons, on a daily basis.
    eg. Run the same query for Variable value BMABRM, then BMASRM, etc...
    In a loop fashion.
    Do not need to set a process chain to trigger broadcaster, or rather simply to schedule the broadcaster to run daily.
    I would basically then want to run this (cache) query in an iterative fashion, ie. rerun it for all the sites.
    Can you please make a recommendation to which is the best approach, whether a process chain should be set up, and any experience you may have had setting up a query to rerun for different variable values.  We would of course want the query to run successfully before rerunning it for the next variable to avoid locks, etc.
    Thank you in advance.
    Simon

    Hi Rahul,
    i have been trying to use the process chain functionality to do this but unsure how to do it.
    Which objects do you use in the process chain:
    Trigger Event Data Change (for Broadcaster)
    or Execute APD Model
    or Precalculation of Web Templates
    i am unsure how to incorporate the queries into the process chain.
    If you have any steps , it would be much appreciated.
    Thank you.
    Simon

  • Querying for custom picklist values

    Hello all,
    I have created a new field on my opportunity type called "Industry" and gave it picklist values. However, the system is not allowing me to query for the values using the Picklist web service. Am I missing a step here, or does the system not allow querying for custom picklist field values? I can get to certain lists of picklist values for Opportunity (Type, Probability, some others) but not the picklist I created. Am I doing something wrong?
    Thanks!
    -Kevin Green

    Hi,
    Find integration tag for custom field in Field Setup. When you call getPicklist method, pass three values like Object type(ex: Lead), integratin tag for the custom field, "" ( this is language, this field is no need for English languague)
    Hope this willl work
    Raja Kumar Malla
    [email protected]

  • Precalculated Value Set

    Hi,
    I am trying to do the setting for Precalculated Value Set....I have a Query with variables...But the problem is I am not able to see the characterisitic in the left window of Reporting Agent(Value Sets)....Any help is appreciated......

    Shreya
    I am not sure why it's not showing up but you could create your own characteristics by clicking create new settings button and assign reporting agent.
    Thnaks
    Sat

Maybe you are looking for

  • Edit Cell Numeric Attributes may show strange default values

    Those values look a bit surprising... I did not type them myself... It happens if you change the data type let's say from unsigned char to double... But it's not a meaningless number: if you now type -1e1000 as a new minimum value, CVI 'corrects' it

  • System copy using oracle backup/restore - sapinst does not restart after re

    I am performing a system copy of a BW3.5 system, using the system copy procedures and Oracle backup/restore. on the target node, I have installed the CI. I have run sapinst to install the database up to the point when it tells me to install the Oracl

  • Express 34 Firewire 800

    Is one available yet? If so where?

  • Detatched PDF generation

    I have a requirement to capture a PDF report at a scheduled time (ie out of hours) and store on the DB. The reason behind this is that the data is purged every few hours (hundreds of millions of rows) and so they would like to capture the stats befor

  • Format of table displayed using h:panelGrid tag

    Hi , I want to display a table using h:panelGrid as below Account Information - This is the caption for the table Account Name : bola Account Number: 12345 <h:panelGrid columns="2"              cellspacing="0"              styleClass="abc"> <f:facet