SQL query according to shore

All,

I have the task 3A, B and C, each task have different coastal
Task has higer priority task and then B, then c. task

Scenario #1:
ClientID - tNom - sdate - edate
-100a - 20 Jan 11-22 Jan 11
100 - B - 22 Jan 11 - null value

in this task has a higer priority then the task B, so the result should be:
-100a - 20 Jan 11 - null

Scenario #2:
ClientID - tNom - sdate - edate
200 - a - 25 Jan 11-25 Jan 11
200 - B - Jan 25, 11-25 Jan 11
200 - C - 25 Jan 11 - null

in this scenario, all tasks start and end the same day, so the final result should be:
200 - a - 25 Jan 11-25 Jan 11
200 - B - Jan 25, 11-25 Jan 11
200 - C - 25 Jan 11 - null

Scenario No. 3:
ClientID - tNom - sdate - edate
400 C - 1 Mar Mar 11-6 11
-400 B - 6 Mar 11 - null

in this scenario, task B has a right-of-way higer then task C, result should be:
-400 B - 6 Mar 11 - null

SQL for all scenarios: Pls help to do it by means of sql or a procedure or a function.

WITH task_dtl AS
(SELECT 100 client_id, 'A' tname, to_date('20/1/2011','DD/MM/YYYY') stdate, to_date('22/1/2011','DD/MM/YYYY') edate OF DOUBLE UNION ALL
SELECT tNom 100, 'B', to_date As (' 1/22/2011 ',' DD/MM/YYYY'), NULL edate OF DOUBLE UNION ALL
SELECT 200, 'A' tname, to_date('25/1/2011','DD/MM/YYYY') stdate, to_date('25/1/2011','DD/MM/YYYY') edate OF DOUBLE UNION ALL
SELECT 200, 'B' tname, to_date('25/1/2011','DD/MM/YYYY'), to_date('25/1/2011','DD/MM/YYYY') etdate OF DOUBLE UNION ALL
SELECT 200 'C' tNom, to_date (January 25, 2011 ',' DD/MM/YYYY ') As, NULL edate OF DOUBLE UNION ALL
SELECT 300, 'A' tname, to_date As (' 2/20/2011 ',' DD/MM/YYYY'), NULL edate OF DOUBLE UNION ALL
SELECT 400, 'C' tname, to_date('1/3/2011','DD/MM/YYYY') stdate, to_date('6/3/2011','DD/MM/YYYY') edate OF DOUBLE UNION ALL
SELECT tNom 400, 'B', to_date (' 6/3/2011 ',' DD/MM/YYYY') got, NULL FROM DUAL edate
)
SELECT * FROM task_dtl;


Thank you

The logical combination all weird, I guess (wildly guessing!) something like that...

SQL> ed
Wrote file afiedt.buf

  1  WITH task_dtl AS
  2    (SELECT 100 client_id, 'A' tname ,to_date('20/1/2011','DD/MM/YYYY') sdate,to_date('22/1/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
  3     SELECT 100 , 'B' tname ,to_date('22/1/2011','DD/MM/YYYY') stdate ,NULL edate FROM DUAL UNION ALL
  4     SELECT 200 ,'A' tname ,to_date('25/1/2011','DD/MM/YYYY') stdate,to_date('25/1/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
  5     SELECT 200, 'B' tname ,to_date('25/1/2011','DD/MM/YYYY'),to_date('25/1/2011','DD/MM/YYYY') etdate FROM DUAL UNION ALL
  6     SELECT 200, 'C' tname ,to_date('25/1/2011','DD/MM/YYYY')stdate ,NULL edate FROM DUAL UNION ALL
  7     SELECT 300 , 'A' tname ,to_date('20/2/2011','DD/MM/YYYY') stdate , NULL edate FROM DUAL UNION ALL
  8     SELECT 400 , 'C' tname ,to_date('1/3/2011','DD/MM/YYYY') stdate,to_date('6/3/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
  9     SELECT 400 , 'B' tname ,to_date('6/3/2011','DD/MM/YYYY') stdate ,NULL edate FROM DUAL
 10    )
 11  --
 12  select client_id, tname, sdate, edate
 13  from (
 14        select client_id, tname, sdate, edate, dt_rnk, tn_rnk
 15              ,case when count(*) over (partition by client_id) = count(*) over (partition by client_id, dt_rnk) then 1 else 0 end as cnt
 16        from (
 17              SELECT client_id
 18                    ,tname
 19                    ,sdate
 20                    ,case when sdate != edate then
 21                       first_value(edate) over (partition by client_id order by edate nulls first)
 22                     else edate
 23                     end as edate
 24                    ,dense_rank() over (partition by client_id order by sdate) as dt_rnk
 25                    ,dense_rank() over (partition by client_id order by tname) as tn_rnk
 26              FROM task_dtl
 27              )
 28       )
 29  where cnt = 1 or tn_rnk = 1
 30* order by client_id, sdate, tname
SQL> /

 CLIENT_ID T SDATE                EDATE
---------- - -------------------- --------------------
       100 A 20-JAN-2011 00:00:00
       200 A 25-JAN-2011 00:00:00 25-JAN-2011 00:00:00
       200 B 25-JAN-2011 00:00:00 25-JAN-2011 00:00:00
       200 C 25-JAN-2011 00:00:00
       300 A 20-FEB-2011 00:00:00
       400 B 06-MAR-2011 00:00:00

6 rows selected.

SQL>

Tags: Database

Similar Questions

  • SQL query for retrieving data based on Certain model

    Hi all

    I want to retrieve all the identifiers of all the people who are permanently seated during the last hour.

    Data are expressed as below:

    -Creation of the activity Table

    CREATE TABLE activity_log

    (

    Username, NUMBER of

    Activity VARCHAR2 (30),

    StartTime VARCHAR2 (6).

    EndTime VARCHAR2 (6)

    );

    -Filling with sample data

    INSERT INTO activity_log VALUES('39','Walking','09:01','09:05');

    INSERT INTO activity_log VALUES('39','Walking','09:06','09:10');

    INSERT INTO activity_log VALUES('39','Sitting','09:11','09:15');

    INSERT INTO activity_log VALUES('39','Sitting','09:16','09:20');

    INSERT INTO activity_log VALUES('39','Sitting','09:21','09:25');

    INSERT INTO activity_log VALUES('39','Standing','09:26','09:30');

    INSERT INTO activity_log VALUES('39','Standing','09:31','09:35');

    INSERT INTO activity_log VALUES('39','Sitting','09:36','09:40');

    INSERT INTO activity_log VALUES('39','Sitting','09:41','09:45');

    INSERT INTO activity_log VALUES('39','Sitting','09:46','09:50');

    INSERT INTO activity_log VALUES('39','Sitting','09:51','09:55');

    INSERT INTO activity_log VALUES('39','Sitting','09:56','10:00');

    INSERT INTO activity_log VALUES('39','Sitting','10:01','10:05');

    INSERT INTO activity_log VALUES('39','Sitting','10:06','10:10');

    INSERT INTO activity_log VALUES('39','Sitting','10:11','10:15');

    INSERT INTO activity_log VALUES('39','Sitting','10:16','10:20');

    INSERT INTO activity_log VALUES('39','Sitting','10:21','10:25');

    INSERT INTO activity_log VALUES('39','Sitting','10:26','10:30');

    INSERT INTO activity_log VALUES('39','Sitting','10:31','10:35');

    INSERT INTO activity_log VALUES('39','Standing','10:36','10:40');

    INSERT INTO activity_log VALUES('39','Standing','10:41','10:45');

    INSERT INTO activity_log VALUES('39','Walking','10:46','10:50');

    INSERT INTO activity_log VALUES('39','Walking','10:51','10:55');

    INSERT INTO activity_log VALUES('39','Walking','10:56','11:00');

    INSERT INTO activity_log VALUES('40','Walking','09:01','09:05');

    INSERT INTO activity_log VALUES('40','Walking','09:06','09:10');

    INSERT INTO activity_log VALUES('40','Sitting','09:11','09:15');

    INSERT INTO activity_log VALUES('40','Sitting','09:16','09:20');

    INSERT INTO activity_log VALUES('40','Sitting','09:21','09:25');

    INSERT INTO activity_log VALUES('40','Standing','09:26','09:30');

    INSERT INTO activity_log VALUES('40','Standing','09:31','09:35');

    INSERT INTO activity_log VALUES('40','Sitting','09:36','09:40');

    INSERT INTO activity_log VALUES('40','Sitting','09:41','09:45');

    INSERT INTO activity_log VALUES('40','Sitting','09:46','09:50');

    INSERT INTO activity_log VALUES('40','Sitting','09:51','09:55');

    INSERT INTO activity_log VALUES('40','Walking','09:56','10:00');

    INSERT INTO activity_log VALUES('40','Sitting','10:01','10:05');

    INSERT INTO activity_log VALUES('40','Standing','10:06','10:10');

    INSERT INTO activity_log VALUES('40','Standing','10:11','10:15');

    INSERT INTO activity_log VALUES('40','Walking','10:16','10:20');

    INSERT INTO activity_log VALUES('40','Walking','10:21','10:25');

    INSERT INTO activity_log VALUES('40','Walking','10:26','10:30');

    INSERT INTO activity_log VALUES('40','Sitting','10:31','10:35');

    INSERT INTO activity_log VALUES('40','Sitting','10:36','10:40');

    INSERT INTO activity_log VALUES('40','Sitting','10:41','10:45');

    INSERT INTO activity_log VALUES('40','Standing','10:46','10:50');

    INSERT INTO activity_log VALUES('40','Walking','10:51','10:55');

    INSERT INTO activity_log VALUES('40','Walking','10:56','11:00');

    Based on the data, the user ID 39 must be found, since it's been sitting since 09:36-10:35, which is continuous 1 hour.

    Any guidance how to do using SQL query will be of great help and appreciation.

    Thank you very much

    Kind regards

    Bilal

    So what exactly is wrong with the request that I already gave you?

    Just to remind one untested (because of lack of insert statements) rewrite according to your new data:

    with grp as)

    Select

    username

    UserRecognizedActivityID activity

    starttime

    starttime + endetime + 1

    row_number() over (partition by order of starttime userid)

    -ROW_NUMBER() over (partition of userid, UserRecognizedActivityID order of starttime)

    RN

    of activity_log

    )

    Select

    username

    min (starttime) starttime

    max (endtime) endtime

    max (activity) activity

    GRP

    Group userid, rn

    with round (max (endtime) - min (starttime) * 24 * 60) > = 59

  • SQL query must count number of engaged, end, MEP per month

    Hi all

    Need Sql query with group by category and count of the PEM attached, terminated, current for every month for the year.

    Create table per_all_people_f
    (person_id varchar2(30),
    original_date_of_hire date)
    
    Create table per_all_assignments_f
    (person_id varchar2(30),
    employee_category varchar2(30))
    
    create table per_periods_of_service
    (person_id varchar2(30),
    actual_termination_date date)
    
    insert into per_all_people_f
    values(1,to_date('01-FEB-2014','DD-MON-YYYY'));
    /
    insert into per_all_people_f
    values(2,to_date('10-FEB-2014','DD-MON-YYYY'));
    /
    insert into per_all_people_f
    values(3,to_date('10-dec-2013','DD-MON-YYYY'));
    /
    insert into per_all_people_f
    values(4,to_date('10-MAR-2014','DD-MON-YYYY'));
    /
    insert into per_all_people_f
    values(5,to_date('10-dec-2013','DD-MON-YYYY'));
    /
    
    
    insert into per_all_assignments_f
    values(1,'ADMIN');
    /
    insert into per_all_assignments_f
    values(2,'TECH');
    /
    
    insert into per_all_assignments_f
    values(3,'TECH');
    /
    insert into per_all_assignments_f
    values(4,'ADMIN');
    /
    
    insert into per_all_assignments_f
    values(5,'ADMIN');
    /
    
    insert into per_periods_of_service
    values(3,to_date('05-feb-2014','DD-MON-YYYY'));
    /
    
    
    
    
    
    
    
    
    
    

    Desired output.  "()" are to explain only.

    Explanation of columns:

    Hired_ADMIN = used category ADMIN

    Term _Admin = employee fired from category ADMIN

    Current_ADMIN = Total current employees in category ADMIN

    Hired_TECH = used in category TECH

    Term_TECH = employee fired in category TECH

    Current_TECH = Total current employees in category TECH

                      
    
                 
    Month        Hired_ADMIN   Term_ADMIN     Current_ADMIN                        Hired_TECH    Term_TECH      Current_TECH
    
    
    Jan-14          0             0                1                                   0            0                10 (example)
    Feb-14         2              1                2                                   0            1                 9
    
    
    
    

    Tried the queries below: but not able to get the desired output grouping...

    I made different requests for In (Hired), Out (Terminated), need help for current employees by month and grouping as stated above the desired output.

    1 request for employees

    
    
    select in_month,in_month_name
             , count(decode(employee_category,'ADMIN', person_id)) ADMIN_IN
             --, count(decode(employee_category,'DOCT', person_id)) DOCT_IN
             --, count(decode(employee_category,'NURS', person_id)) NURS_IN
             , count(decode(employee_category, 'TECH', person_id)) TECH_IN
    from
    (
    select distinct
    papf.person_id,
    paaf.employee_category,
           trunc(papf.original_date_of_hire, 'mm') in_month,
           decode(userenv('LANG'),'US',to_char(papf.original_date_of_hire, 'Month'),'AR',to_char(papf.original_date_of_hire, 'Month','nls_date_language=Egyptian'),'') in_month_name
          from per_all_people_f papf
          ,per_all_assignments_f paaf
          where papf.person_id = paaf.person_id
          and Papf.ORIGINAL_DATE_OF_HIRE between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR)
          and paaf.employee_category is not null         
           )           
         group
          by in_month,in_month_name  
         ORDER BY  in_month
    
    
    
    

    2. request for completed employees:

    select out_month,out_month_name
             , count(decode(employee_category,'ADMIN', person_id)) ADMIN_OU
             --, count(decode(employee_category,'DOCT', person_id)) DOCT_OUT
             --, count(decode(employee_category,'NURS', person_id)) NURS_OUT
             , count(decode(employee_category, 'TECH', person_id)) TECH_OUT
    from
    (
    select distinct
           papf.person_id,
           paaf.employee_category,
           trunc(actual_termination_date,'mm') out_month,
           decode(userenv('LANG'),'US',to_char(actual_termination_date, 'Month'),'AR',to_char(actual_termination_date, 'Month','nls_date_language=Egyptian'),'') out_month_name
          from per_all_people_f papf
          ,per_all_assignments_f paaf
          ,per_periods_of_service ppos
          where papf.person_id = paaf.person_id
          and ppos.person_id = papf.person_id
          and ppos.actual_termination_date between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR)
          and paaf.employee_category is not null             
           )           
         group
          by out_month,out_month_name  
         ORDER BY  out_month
    
    
    
    

    Pls suggest the sql query for current employees monthly and Hired of the EMP, Terminated the PEM group, according to the current EME Emp_Category.

    Please suggest...

    Thanks and greetings

    Afzal.

    Post edited by: 1002933

    Try this:

    set line 1000
    
    WITH dt AS
            (SELECT TO_DATE ('01/' || LEVEL || '/' || &p_year, 'dd/mm/yyyy')
                       st_dt
               FROM DUAL
             CONNECT BY LEVEL <= 12)
    SELECT mnth
          ,hired_admin
          ,term_admin
          ,hired_admin - term_admin current_admin
          ,hired_tech
          ,term_tech
          ,hired_tech - term_tech current_tech
      FROM (SELECT TO_CHAR (st_dt, 'mon-yy') mnth
                  , (SELECT COUNT (*)
                       FROM per_all_people_f h, per_all_assignments_f c
                      WHERE h.person_id = c.person_id
                        AND c.employee_category = 'ADMIN'
                        AND h.original_date_of_hire BETWEEN st_dt
                                                        AND LAST_DAY (st_dt))
                      hired_admin
                  , (SELECT COUNT (*)
                       FROM per_all_people_f h
                           ,per_all_assignments_f c
                           ,per_periods_of_service s
                      WHERE h.person_id = c.person_id
                        AND c.employee_category = 'ADMIN'
                        AND h.person_id = s.person_id
                        AND s.actual_termination_date BETWEEN st_dt
                                                          AND LAST_DAY (st_dt))
                      term_admin
                  , (SELECT COUNT (*)
                       FROM per_all_people_f h, per_all_assignments_f c
                      WHERE h.person_id = c.person_id
                        AND c.employee_category = 'TECH'
                        AND h.original_date_of_hire BETWEEN st_dt
                                                        AND LAST_DAY (st_dt))
                      hired_tech
                  , (SELECT COUNT (*)
                       FROM per_all_people_f h
                           ,per_all_assignments_f c
                           ,per_periods_of_service s
                      WHERE h.person_id = c.person_id
                        AND c.employee_category = 'TECH'
                        AND h.person_id = s.person_id
                        AND s.actual_termination_date BETWEEN st_dt
                                                          AND LAST_DAY (st_dt))
                      term_tech
              FROM dt);
    

    Output:

    Enter the value of p_year: 2014

    old 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || & p_year, ' dd/mm/yyyy') st_dt

    new 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || 2014, ' dd/mm/yyyy') st_dt

    MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH

    --------------- ----------- ---------- ------------- ---------- ---------- ------------

    Jan-14                    0          0             0          0          0            0

    Feb-14                    1          0             1          1          1            0

    Mar-14                    1          0             1          0          0            0

    Apr-14                    0          0             0          0          0            0

    May-14                    0          0             0          0          0            0

    Jun-14                    0          0             0          0          0            0

    Jul-14                    0          0             0          0          0            0

    Aug-14                    0          0             0          0          0            0

    Sep-14                    0          0             0          0          0            0

    Oct-14                    0          0             0          0          0            0

    Nov-14                    0          0             0          0          0            0

    MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH

    --------------- ----------- ---------- ------------- ---------- ---------- ------------

    Dec-14                    0          0             0          0          0            0

    12 selected lines.

  • What will happen to the SQL Query based object View (EmployeesVO)

    Schema used: HR

    1. I created a view through SQL Query view object object (Table Employees - EmployeesVO).
    2. Creates an entity of the Employees (EmployeesEO) table object.
    3. In the section EmployeesVO (View object) entity objects, I chose EmployeesEO (entity object).

    What will happen to the View SQL Query object based on (EmployeesVO) will it change to VO based on entities or still to be based query VO.

    It is there because you can still base your query based Vo EO according to Vo.

    After that you base your VO on EO you can now use 'Add the attribute of the entity' to base your attribute on the atrributes of EO. Or if you skilled enough you can manually change the XML to VO

  • SQL query and question CFOUTPUT

    Hello

    I am trying to compare two tables in a database.  I need a few fields in a table of output, to compare a field between the two tables.  Users choose the tables.  I've written a SQL query that does what I need:

    < cfquery name = "getitems" datasource = "snapshot" >
    Select #endtable # .field9 #endtable # .field12, #endtable # .field4, #endtable # .field13, #endtable # .field2, #endtable # .field3, #starttable # .field3
    of #endtable #, #starttable #.
    "where #endtable # .field5 =' #form.field5 #"
    and #starttable # .field2 = #endtable # .field2
    < / cfquery >

    Problem is on the output.  You can see that I am selecting field3 in two tables.  I want also to two output field3 values.

    < cfoutput query = "getitems" >

    #field3 #.

    < / cfoutput >

    This gives me the value that was chosen as #endtable # .field3.

    How can I exit the other - .field3 of # #starttable?

    As mentioned, the table names are variable being passed in the query...  Thank you!

    Peter

    How can I exit the other - .field3 of # #starttable?

    Use an alias to give different names fields IE table.column AS unnom. Otherwise, cfquery do not know what field do you mean when you say "field3".

    Select #endtable # .field9, #endtable # .field12,.

    Be careful when using this type of sql. According to the source of your variables, this can pose a risk of sql injection.

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • A difficult dynamic SQL query problem

    Hi all

    I have a very interesting problem to work:

    We have this special table defined as follows:

    CREATE TABLE sales_data)
    sales_id NUMBER,
    NUMBER of sales_m01
    NUMBER of sales_m02
    NUMBER of sales_m03
    NUMBER of sales_m04
    NUMBER of sales_m05
    NUMBER of sales_m06
    NUMBER of sales_m07
    NUMBER of sales_m08
    NUMBER of sales_m09
    NUMBER of sales_m10
    NUMBER of sales_m11
    NUMBER of sales_m12
    sales_prior_yr NUMBER);
    /

    Columns ' sales_m01... sales_m12' represents aggregated monthly sales, what "sales_m01" is translated by "sales for the month of January, January is the first month,"sales_m02"in sales for the month of February and so on.»

    The problem I encounter is that we have a project that requires that a parameter is passed to a stored procedure that represents the number of months which is then used to create a SQL query with aggregations of next mandatory field, which depends on the parameter passed:

    Example 1: entry of parameter: 4
    Should be built dynamically to SQL query:

    SELECT
    Sum (sales_m04) as CURRENT_SALES,
    Sum (sales_m01 + sales_m02 + sales_m03 + sales_m04) SALES_YTD
    Of
    sales_data
    WHERE
    sales_id = '0599768';

    Example 2: input parameter: 8
    Should be built dynamically to SQL query:

    SELECT
    Sum (sales_m08) as CURRENT_SALES,
    SUM (sales_m01 + sales_m02 + sales_m03 + sales_m04 +)
    sales_m05 + sales_m06 + sales_m07 + sales_m08) SALES_YTD
    Of
    sales_data
    WHERE
    sales_id = '0599768';


    So in a sense, the contents of SUM(sales_m01...n) would vary according to the parameter, which must be a number between 1... 12 what is a month, which in turn corresponds to a range of real field on the table itself. The resulting dynamic query should include only those columns/fields in the table that is within the range given by the input parameter and does not account for all the other columns/fields.

    Any solution is greatly appreciated.

    Thank you.
    SQL> declare
      cols long;
      param integer := 6;
      sales_id integer := 0599768;
    begin
      for i in 1..param loop
        cols := cols || 'sales_m' || to_char(i, 'fm00') || '+';
      end loop;
    
      dbms_output.put_line('select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,'+') || ') sales_ytd from sales_data WHERE sales_id = :1');
    end;
    /
    select sum(sales_m06) current_sales, sum(sales_m01+sales_m02+sales_m03+sales_m04+sales_m05+sales_m06) sales_ytd from sales_data WHERE sales_id = :1
    PL/SQL procedure successfully completed.
    

    Now it should be obvious:
    Instead of dbms_output OPEN a refcursor:

    SQL> declare
      cols long;
      param integer := 6;
      sales_id integer := 0599768;
      cur sys_refcursor;
    begin
      for i in 1..param loop
        cols := cols || 'sales_m' || to_char(i, 'fm00') || ',';
      end loop;
    
      open cur for 'select sum(sales_m'||to_char(param,'fm00')||') current_sales, sum(' || rtrim(cols,',') || ') sales_ytd from sales_data WHERE sales_id = :1' using sales_id;
      .....
    end;
    /
    

    Published by: michaels2 on July 26, 2009 09:49

    replaced ',' with ' + '.

  • Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit

    I have this SQL query:

    DECLARE TABLE (@DataTypeTable)
    Name varchar (128).
    TypeID INT)

    -Add comma delimeted type data in the temporary table names
    INSERT INTO @DataTypeTable (name)
    SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')

    SELECT the name OF @DataTypeTable

    That takes a comma delimited by the string and returns the string as a table.  It works correctly in Microsoft SQL Server Management Studio.  When I run this as a stored procedure I return nothing.  There are no errors, SQL or otherwise.  I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above).  Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?

    Thanks in advance.


  • LabVIEW sql query

    HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.

    As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock

    There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
    Help me pls!

    with respect,

    Ray

    Hello

    You have two cases:

    (1) connect to the database with string (link a string of connection information), and then type something like this:
    Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)

    (2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.

    There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl

    Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.

    Kind regards

  • SQL query for empty string

    I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.

    I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.

    Thanks in advance for your help,

    Jim

    Jim,

    Just to be sure, have you used 'is' instead of '=' in this command?

    This makes all the difference in this command.

    Cerati

  • Support of SQL query: what tasks are Sunday from 07:00 - 12:00

    Hello tide Admins.

    I need to do a SQL query that can give me a list of jobs that are running on a given (Sunday) day from 07:00 - 12:00.  Our environment is not a maintenance window.  Therefore, whenever there is application of patches or upgrades, it causes more work and risk of failure of the tide tasks.    By moving jobs over the period from 07:00 - 12:00 Sunday, patch can be completed without disrupting the calendar.

    Im not the best at the SQL script and can not get my script to work. any help would be great. Here's what I have so far.  I get the error ' could not find identifier multi-player jobmst.jobmst_name.  IM using Tidal 6.0.3 with SQL for DB Admeral table.

    SELECT dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name

    FROM dbo.jobdtl INNER JOIN

    dbo.jobmst ON dbo.jobdtl.jobdtl_id = dbo.jobmst.jobdtl_id

    WHERE (dbo.jobdtl.jobdtl_fromdt > 14 September 2016 06:00 ') AND (dbo.jobdtl.jobdtl_fromdt< '09/11/2016="" 012:00:00="">

    GROUP OF dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name

    Hi Jeff

    The time window from the jobdtl returns only jobs that have an early start time and windows of time from beginning to the end, so there may be some tasks which are not time bound but have dependencies on other jobs, variables, etc.

    Here are the 2 SQL queries against the table jobrun and jobmst:

    -The list of jobs that took place last Sunday between 07:00 and 12:00

    SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_time FROM jobrun
    JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
    WHERE jobrun.jobrun_time > = 9/11/2016 07:00 ' and jobrun.jobrun_time<= '9/11/2016="" 12:00="">
    ORDER BY jobrun.jobrun_time

    -For a list of jobs that are scheduled to run on Sunday to come between 07:00 and 12:00

    SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_esttime FROM jobrun
    JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
    WHERE jobrun.jobrun_esttime > = 9/18/2016 07:00 ' and jobrun.jobrun_esttime<= '9/18/2016="" 12:00="">
    ORDER BY jobrun.jobrun_esttime

    ARO

    The Derrick

  • How to get the value of a column in sql query?

    Hi, anyone knows how to get the value of a column in sql query?

    Here is my code, the value must be 1350079224397 in my PB, but I get 0

    QString query ("SELECT version FROM db_version");

    QVariant result = sda.execute (query);
    QVariantMap versionMap = result.toList () such () .toMap ();
    If (! versionMap.IsEmpty ())
    {
    qDebug()<"Version: "=""><>
    }

    OK, I have the solution

    QString query ("SELECT version as version FROM db_version");

  • Looking for a SQL query to retrieve callvariables + ECC to a RESULTS of SCRIPT EXECUTE (translation VRUS)

    Hi team,

    I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.

    In my view, that the data are analyzed between the termination call detail + termination call Variable.

    If you have already such a SQL query I would be very grateful to have.

    Thanks and greetings

    Nick

    Omar,

    respectfully, shorten the interval of a day might not be an option for a history report ;-)

    I recommend to take a look at the following SQL query:

    DECLARE @dateFrom DATETIME, @dateTo DATETIME

    SET @dateFrom = ' 2014-01-24 00:00:00 '

    SET @dateTo = ' 2014-01-25 00:00:00 '

    SELECT

    TCV. DateTime,

    TCD. RecoveryKey,

    TCD. RouterCallKeyDay,

    TCD. RouterCallKey,

    VME. EnterpriseName AS [ECVEnterpriseName],

    TCV. ArrayIndex,

    TCV. ECCValue

    OF Termination_Call_Variable tcv

    JOIN THE

    (SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">

    THE tcv. TCDRecoveryKey = tcd. RecoveryKey

    LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID

    WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>

    With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).

    In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.

    Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).

    G.

  • DA on updatable report items Sql query using the class

    Request Express 4.2.5.00.08

    10-11 g Oracle

    I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.


    However, I've now added some complex things.

    for example. My region is based on the query of SQL Type (editable report).

    SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;

    I can also add a new line of course.

    My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.

    for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.

    And now, I created the DA.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    1. action: set value

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    The element affected: P10_X1 (it is a hidden item)

    2. action: Plsql Code

    Code: start to null; end;

    Page items to submit: P10_X1

    3. action: Plsql Code

    Code: start

    If: P10_X1 between '03' AND '11' then

    : P10_X1: = 'EARLIES ';

    elsif: P10_X1 then '12' and '18'

    : P10_X1: = 'LATES ';

    on the other

    : P10_X1: = 'NIGHTS';

    end if;

    end;

    Page items to submit: P10_X1

    NOW another DA

    Event: change

    Article (s) P10_X1

    Condition (in list)

    value (HASTY, LATES, NIGHTS)

    Action:

    Set type: Expression Javascript

    The JavaScript Expression: $(this.triggeringElement) .val ();

    Affected item:

    Selection type: jQuery Selector

    jQuery Selector:. Shift_time

    Well, I look forward all the above work well, but I'm having a problem.

    If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.

    I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?

    Help, please!

    Kind regards

    RI

    I found the solution me thank you.

    I removed all the DA mentioned above and created a new.

    1. event: change

    Selection type: jQuery Selector

    jQuery Selector: .st_tm

    Condition: No.

    Scope of the event: dynamic and light on page load.

    Action (Javascript code)

    ROW_ID = $(this.triggeringElement).attr('id').substr (4);

    If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">

    .Val ('EARLIES') $(«#f11_» + row_id);

    }

    ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">

    .Val ('LATES') $(«#f11_» + row_id);

    }

    ElseIf (. val() > $19 (this.triggeringElement)) {}

    .Val ('NIGHTS') $(«#f11_» + row_id);

    }

    also created another DA because I have a disabled report items.

    Event: before the page is sent.

    $('_:_disabled').removeAttr ("disabled");

    and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).

    Kind regards.

  • SQL query to retrieve only numbers to a string variable

    Dear all Experts,

    I have a requirement in one of my projects where I need to extract only the numbers present in the variable.

    for example:

    BANK_ACCOUNT_NUMBER = 12345-67890';

    BANK_ACCOUNT_NUMBER = 12345 67890';

    BANK_ACCOUNT_NUMBER = "123.456.7890";

    BANK_ACCOUNT_NUMBER = 123-A456BC7890D';


    In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.


    Please suggest me the query how to extract numeric values from varchar variable.



    Thank you

    Knockaert

      select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
    

    See you soon,.

    Manik.

Maybe you are looking for

  • Sick of be charged twice...

    How can I configure my account of music for my family and me can get charged the monthly $ 15 instead of $10 per device?

  • Why firefox is always problem when I put cache 0 MB Web site?

    Hello I develop Web sites and about 1 month, I think that to the top of the Version 30 or 31 have problems with the cache. I activated the manual cache size and set it to 0MB (Web sites), but I still have problems that a site is cached. In developmen

  • Problem with M30 power indicator

    Hi I have a satellite m30 and when I plug my power adapter, battery indicators starting to keep flashing (all of 3 leds flashing) and it does not load. I tried to remove the battery and plug in the adapter again the LED indication has stopped working

  • Lenovo G470 keeps stopping during playback of videos for internet spontaneously

    Hello I have a Lenovo older G470 of 1 week I've discovered recently guard spontaneously stopping during playback of the facebook/youtube videos. This occurs regardless if I'm on battery or connected to AC power. My G470 has an i5 - 2410M with 8 GB me

  • No office at startup, can't see my mouse cursor

    I had all sorts of problems with windows 10 so I re charge my disc of windows 7 and formatted my hard drive.  Everything booted up great and I did not add any software for 3 days to make sure that windows works fine.  Before formatting, I don't have