Select Max (date) multiple records

I'm having a problem getting the last value for several gauges.  Here's my query:

SELECT parameter_id,

TS_ID,

value,

Location_id,

Date_Time

Of

MyTable

JOIN IN-HOUSE

mytable2

WE

TS_ID = ts_id

WHERE

TS_ID LIKE '% - rev.

unit_id = ("pi")

the value IS NOT NULL

Location_id as "xxxx".

Date_Time =

(SELECT Max (date_time)

My TABLE

GROUP BY parameter_id)

;

Hello

A scalar subquery, such as the expression to the right of the sign =

Date_Time = (SELECT...)

must produce (at most) only 1 row.  If the subquery produces 2 or more lines, it will trigger an error.

Given that you are using "GROUP BY parameter_id" in the subquery, it will produce a separate line of output for each distinct value of parameter_id.  You can use a correlated subquery at that time, that only looks like a parameter_id, or you can use a subquery IN, like this:

WHERE (parameter_id, Date_Time) IN

(

SELECT parameter_id

MAX (date_time)

FROM MyTable

GROUP BY parameter_id

)

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

Tags: Database

Similar Questions

  • Select Max (date) between multiple tables

    I need to retrieve a record from a Table in a set of similar tables with a common "date field". You can select the record where this "date field" value is greater between multiple tables.

    Here, any help is appreciated.  Thank you in advance.

    FOR EXAMPLE

    No. EMP is the primary key.

    Again, each table can have multiple records for EMP n ° 1

    TABLE1:

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    BASE SALARY

    DATE_FROM

    TABLE 2

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    SALARY GRADE

    DATE_FROM

    TABLE 3

    FIRST NAME

    FAMILY NAME
    THE EMP NO.

    COMPENSATION

    DATE_FROM

    Hello

    Said Knani, if you use the current design of the table, then here is a way to do what you want:

    WITH union_data AS

    (

    SELECT MAX (base_salary) AS sal FROM table1 UNION ALL

    SELECT MAX (grade_salary) table2 UNION ALL

    SELECT MAX (compensation) FROM table3

    )

    SELECT MAX (sal) AS max_sal

    Of union_data

    ;

  • Select Max (Date) in two different tables...

    Dear all,

    I need the date of last update of two different tables, I mean max (date). We will update one table at a time. Updated once I need to take the last update.

    It can be either in table A table B.

    for example.

    Table A

    Date of the ID

    100 16/05/2014

    101 20/05/2014

    102, 22/05/2014

    Table B

    Date of the ID

    100 04/06/2014

    101, 26/05/2014

    102 21/05/2014

    I need the date of table B (101 26/05/2014) last updated date...

    Hello

    Another way, using much more GRAND:

    SELECT LARGER (max1, max2) x

    FROM (SELECT MAX (mydate) max1

    OF mytable_a

    )

    (SELECT MAX (myotherdate) max2

    OF mytable_b

    )

    ;

    Best regards

    Bruno Vroman.

  • To summarize two records based on Max Date

    Hello

    I have the following data:

    Account number Date of invoice Invoice Amt Real AMT Companies code
    1001110/11/2013100.0293.030112
    1001110/02/201493.0487.760232

    I need to sum up above two records based on max (Invoice Date) and and I need to display company code corresponding to the date of billing max

    Expected result:

    Account number Date of invoice Invoice Amt Real AMT Companies code
    1001110/02/2014193.06180.790232

    Thank you

    Kiran

    Hello

    Try this:

    with in_data as
    (
    Select '10011' account_number, dates "2013-11-10' invoice_date, invoice_amt 100.02, 93,03 actual_amt '0112' company_code of all the double union"
    Select '10011,' date '' 2014-02-10, 93.04, 87.76, '0232' from dual
    )

    Select
    Account_Number
    max (invoice_date) i_date
    sum (invoice_amt) i_amt
    sum (actual_amt) a_amt
    , max (company_code) Dungeon c_code (last dense_rank command by invoice_date)
    Of
    in_data

    Group
    Account_Number
    ;

    ACCOUNT_NUMBER I_DATE I_AMT A_AMT C_CODE


    -------------- --------- ------ ------ ------
    10011 10 FEBRUARY 14 193.06 180,79 0232

    Kind regards

    Peter

  • date max with multiple joins of tables

    Looking for expert advice on the use of max (date) with multiple joins of tables. Several people have tried (and failed) - HELP Please!

    The goal is to retrieve the most current joined line of NBRJOBS_EFFECTIVE_DATE for each unique NBRJOBS_PIDM. There are several lines by PIDM with various EFFECTIVE_DATEs. The following SQL returns about 1/3 of the files and there are also some multiples.

    The keys are PIDM, POSN and suff

    Select NBRJOBS. NBRJOBS.*,
    NBRBJOB. NBRBJOB.*
    of POSNCTL. Inner join of NBRBJOB NBRBJOB POSNCTL. NBRJOBS NBRJOBS on (NBRBJOB. NBRBJOB_PIDM = NBRJOBS. NBRJOBS_PIDM) and (NBRBJOB. NBRBJOB_POSN = NBRJOBS. NBRJOBS_POSN) and (NBRBJOB. NBRBJOB_SUFF = NBRJOBS. NBRJOBS_SUFF)
    where NBRJOBS. NBRJOBS_SUFF <>'LS '.
    and NBRBJOB. NBRBJOB_CONTRACT_TYPE = 'P '.
    and NBRJOBS. NBRJOBS_EFFECTIVE_DATE =
    (select Max (NBRJOBS1. NBRJOBS_EFFECTIVE_DATE) as 'EffectDate '.
    of POSNCTL. NBRJOBS NBRJOBS1
    where NBRJOBS1. NBRJOBS_PIDM = NBRJOBS. NBRJOBS_PIDM
    and NBRJOBS1. NBRJOBS_POSN = NBRJOBS. NBRJOBS_POSN
    and NBRJOBS1. NBRJOBS_SUFF = NBRJOBS. NBRJOBS_SUFF
    and NBRJOBS1. NBRJOBS_SUFF <>'LS '.
    and NBRJOBS1. NBRJOBS_EFFECTIVE_DATE < = to_date('2011/11/15','yy/mm/dd'))
    order of NBRJOBS. NBRJOBS_PIDM

    Welcome to the forum!

    We don't know what you are trying to do.
    You want all of the columns in the rows where NBRJOBS_EFFECTIVE_DATE is the date limit before a given date (November 15, 2011 in this example) for all rows in the result set with this NBRJOBS_PIDM? If so, here is one way:

    with         GOT_R_NUM     as
    (
         select       NBRJOBS.NBRJOBS.*,
                NBRBJOB.NBRBJOB.*     -- You may have to give aliases, so that every column has a unique name
         ,       rank () over ( partition by  NBRJOBS.NBRJOBS_PIDM
                                   order by      NBRJOBS.NBRJOBS_EFFECTIVE_DATE     desc
                          )             as R_NUM
         from          POSNCTL.NBRBJOB NBRBJOB
         inner join      POSNCTL.NBRJOBS NBRJOBS       on    (NBRBJOB.NBRBJOB_PIDM = NBRJOBS.NBRJOBS_PIDM)
                                            and      (NBRBJOB.NBRBJOB_POSN = NBRJOBS.NBRJOBS_POSN)
                                      and      (NBRBJOB.NBRBJOB_SUFF = NBRJOBS.NBRJOBS_SUFF)
         where       NBRJOBS.NBRJOBS_SUFF             != 'LS'       -- Is this what you meant?
         and        NBRBJOB.NBRBJOB_CONTRACT_TYPE   ='P'
         and       NBRJOBS.NBRJOBS_EFFECTIVE_DATE  <= to_date ('2011/11/15', 'yyyy/mm/dd')
    )
    select       *     -- Or list all columns except R_NUM
    from       GOT_R_NUM
    where       R_NUM          = 1
    order by  NBRJOBS_PIDM
    ;
    

    Normally this site does not display the <>inequality operator; He thinks it's some kind of beacon.
    Whenever you post on this site, use the other inequality operator (equivalent), *! = *.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) for all the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will get better results faster if you always include this information whenever you have a problem.

  • Question to merge data from multiple records

    Hi all, could really use some help here, I tried to fix this for hours now:

    Make 3 different models for labels that I print on the basis of models of labels Avery for InDesign. When I come to my fusion of data on any of them, I select "Multiple records" in the title records per Document Page, but the preview and the actual creation just spits out a single unique label on each new page. For example, I use 2 x 4 "labels on 2 of them, so it should print 10 per page, but instead to put 10 unique labels on a page, it puts each new label on a new page. Therefore, instead of 100 pages for the 1 000 labels that I print, I find myself with 1,000 pages.

    I know a double check of size constraints on the text box and make sure it suits you when duplicated, and to my knowledge, who is seeking as it's nice. I'm also fairly certain that CSV files that I use are in the right format, too. I am quite stuck at this stage as to what I have to do to solve this problem, no guidance would be great. Here are the screenshots of what I'm looking, please let me know if there is anything else I can give you to help diagnose the problem.

    Screen Shot 2012-09-24 at 10.52.08 AM.png

    Screen Shot 2012-09-24 at 10.52.28 AM.png

    Screen Shot 2012-09-24 at 10.52.37 AM.png

    Screen Shot 2012-09-24 at 10.53.17 AM.png

    Screen Shot 2012-09-24 at 10.53.33 AM.png

    I thinnk the best way to deal with this would be to ensure that all the Avery template information on the master page. Let him be active while you do the layout in the upper left position on THE DOCUMENT PAGE, and then assign the master let anything showing that your placholders and art added none.

    Reassign the master model after the merger.

  • Data merge multiple records do not work

    Hi all

    When you try to merge multiple records, the result is the same if I selected just a recording.

    Here's the situation:

    Source file:

    • Excel file with several records, saved as a csv and txt

    The target file:

    • InDesign CS4 file with a single page.
    • framework of a text on the page,
    • a table with the header line and a line of body
    • every cell of body line contains a data field

    I went through all the necessary steps:

    • Choose the data source file (tried with csv and txt, the results are the same) and insert the fields in the table
    • chose "All records" to merge
    • to merge records: selected multiple records

    After choosing "Preview", I see only one record per page, and the new pages are created automatically for EACH record! This is not what I want.

    What I want is for as many records if poster in the table as possible and then to InDesign to create additional if necessary pages.

    What I am doing wrong, or isn't it possible?

    Thank you for all your comments!

    Several records, ID to duplicate everything on the page, so unless there is enough space for all of this, you will get several records.

    Think of it as a frame around all your items, group, then using the step and repeat, except merge data won't allow any element to extend beyond the edge of the drawing page.

  • Help line with MAX Date selection

    The data returned by my query currently looks like this.

    10 100 A 29 FEBRUARY 12

    11 101 OCTOBER 16, 12 B

    12 102 B 5 DECEMBER 12

    13 103 C 23 JANUARY 13

    When the data in the third column is duplicated, I want to only return the line with the most recent date in the 4th column (in this case row 3).

    So what I really want is the following.

    10 100 A 29 FEBRUARY 12

    12 102 B 5 DECEMBER 12

    13 103 C 23 JANUARY 13



    Any help would be greatly appreciated.

    Thank you

    Mark

    Here's a way...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select 10 as the id, 100 such as seq, 'A' as the grp, date '' 2012-02-29 as dt of union double all the)
    2. Select 11, 101, 'B', date '' 2012-10-16 of all the double union
    3. Select 12, 102, 'B', date '' 2012-12-05 Union double all the
    4. Select 13, 103, 'C', date "double ' 2013-01-23)
    5  --
    6 select max (id) keep (dense_rank of the first order by dt desc) as id
    7, max (seq) keep (dense_rank of the first order by dt desc) as seq
    8, grp
    9, max (dt)
    10 t
    11 * grp group
    SQL > /.

    ID SEQ G MAX (DT)
    ---------- ---------- - --------------------
    10 100 WAS FEBRUARY 29, 2012 00:00:00
    12 102 B 5 DECEMBER 2012 00:00:00
    13 103 C 23 JANUARY 2013 00:00:00

  • Web service PLSQL returning multiple records

    Hello

    I am creating a web service using oracle 11 g, which should be able to return multiple records.

    Based on the code and the advice of the samples found on the internet, here is my code:

    CREATE OR REPLACE TYPE test_rec is OBJECT (
        s_nume_adre                    NUMBER ,
        c_eta_civi                     VARCHAR2(4 BYTE),
        l_nom1_comp                    VARCHAR2(40 BYTE),
        l_nom2_comp                    VARCHAR2(40 BYTE),
        l_nom3_comp                    VARCHAR2(40 BYTE),
        l_pren_comp                    VARCHAR2(30 BYTE),
        d_date_nais                    DATE);
    
    
    CREATE OR REPLACE TYPE test_array AS TABLE OF test_rec;
    */
    
    CREATE OR REPLACE PACKAGE test_pkg AS
      function get_rows(snume_adre in number) return test_array;
    END;
    /
    
    CREATE OR REPLACE PACKAGE BODY test_pkg AS
      function get_rows(snume_adre in number) return test_array is
        v_rtn   test_array := test_array(null);
        v_first boolean := true;
    
        cursor c_get_rows(snume_adre in number) is
          SELECT a.s_nume_adre,
                 nvl(a.c_eta_civi, '') c_eta_civi,
                 nvl(a.l_nom1_comp, '') l_nom1_comp,
                 nvl(a.l_nom2_comp, '') l_nom2_comp,
                 nvl(a.l_nom3_comp, '') l_nom3_comp,
                 nvl(a.l_pren_comp, '') l_pren_comp,
                 nvl(a.d_date_nais, to_date('01.01.1900', 'dd.mm.yyyy')) d_date_nais
        FROM bro.z45 a
      where a.s_nume_adre = snume_adre or snume_adre is null;
    
      begin
       
        for rec in c_get_rows(snume_adre) loop
          if v_first then
            v_first := false;
          else
            v_rtn.extend;
          end if;
       
        v_rtn(v_rtn.last) := test_rec(rec.s_nume_adre, rec.c_eta_civi, rec.l_nom1_comp, rec.l_nom2_comp,
                                    rec.l_nom3_comp, rec.l_pren_comp, rec.d_date_nais);
        end loop;   
    
        return v_rtn;
      end;
    END;
    /
    
    --select * from table (test_pkg.get_rows(null));
    
    
    

    I am able to retrieve data using select.

    However, when I try to access its wsdl I get an error:

    < envelope soap: >

    < soap: Body >

    < soap: Fault >

    Client: soap < faultcode > < / faultcode >

    entry processing < faultstring > error < / faultstring >

    < detail >

    < OracleErrors > < / OracleErrors >

    < / details >

    < / soap fault: >

    < / soap: Body >

    < / envelope soap: >

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

    If I comment the function call in the package declaration I get a "correct": wsdl

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

    " < name definitions = targetNamespace"GET_ROWS"=" http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "xmlns =" http://schemas.xmlsoap.org/wsdl/ "xmlns:tns =" http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "container =" http://www.w3.org/2001/XMLSchema "xmlns:soap =" http://schemas.xmlsoap.org/wsdl/SOAP/ "> " ""

    < types >

    " < xsd: Schema targetNamespace = ' http://xmlns.Oracle.com/orawsv/test/TEST_PKG/GET_ROWS "elementFormDefault ="qualified"> "

    < xsd: element name = "GET_ROWSInput" >

    < xsd: complexType >

    < / xsd: complexType >

    < / xsd: element >

    < xsd: element name = "GET_ROWSOutput" >

    < xsd: complexType >

    < / xsd: complexType >

    < / xsd: element >

    < / xsd: Schema >

    < / types >

    < name of message = "GET_ROWSInputMessage" >

    < name of part = "parameters" element = "tns:GET_ROWSInput" / >

    < / message >

    < name of message = "GET_ROWSOutputMessage" >

    < name of part = "parameters" element = "tns:GET_ROWSOutput" / >

    < / message >

    < portType name = "GET_ROWSPortType" >

    < operation name = "GET_ROWS" >

    < input message = "tns:GET_ROWSInputMessage" / >

    < output message = "tns:GET_ROWSOutputMessage" / >

    < / operation >

    < / portType >

    < connection name = "GET_ROWSBinding" type = "tns:GET_ROWSPortType" >

    " < style: soap = transport = 'document' binding ' http://schemas.xmlsoap.org/SOAP/HTTP "/>

    < operation name = "GET_ROWS" >

    < soap: operation soapAction = "GET_ROWS" / >

    < input >

    < soap body parts: = 'settings' use = "literal" / >

    < / Entry >

    < output >

    < soap body parts: = 'settings' use = "literal" / >

    < / output >

    < / operation >

    < / binding >

    < service name = "GET_ROWSService" >

    < documentation > Oracle Web Service < / documentation >

    < name of port = "GET_ROWSPort" binding = "tns:GET_ROWSBinding" >

    " < soap: address location = ' http://server.domain.ch:8080 / orawsv/TEST/TEST_PKG/GET_ROWS "/>

    < / port >

    < / service >

    < / definitions >

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

    Any suspicion that how create and access pl sql web service returning multiple lines?

    I use java not and do not have access to tools such as JDeveloper.

    Thank you!

    The real problem is that collection types are not supported for the return parameters.

    The solution is to wrap the collection into another object.

    Here is an example of work based on your settings:

    CREATE OR REPLACE TYPE test_rec is OBJECT (
      empno  number(4)
    , ename  varchar2(10)
    , hiredate date
    );
    /
    
    CREATE OR REPLACE TYPE test_array AS TABLE OF test_rec;
    /  
    
    CREATE OR REPLACE TYPE test_array_wrapper is OBJECT ( arr test_array );
    /
    
    CREATE OR REPLACE PACKAGE test_pkg AS
      function get_rows(p_deptno in number) return test_array_wrapper;
    END;
    /  
    
    CREATE OR REPLACE PACKAGE BODY test_pkg AS
      function get_rows(p_deptno in number) return test_array_wrapper is
        results  test_array;
      begin  
    
        select test_rec(empno, ename, hiredate)
        bulk collect into results
        from scott.emp
        where deptno = p_deptno;     
    
        return test_array_wrapper(results);
      end;
    END;
    /
    

    The wsdl is then generated correctly:

    SQL> select httpuritype('http://DEV:dev@localhost:8080/orawsv/DEV/TEST_PKG/GET_ROWS?wsdl').getxml() from dual;
    
    HTTPURITYPE('HTTP://DEV:DEV@LOCALHOST:8080/ORAWSV/DEV/TEST_PKG/GET_ROWS?WSDL').GETXML()
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
      
        
          
            
              
                
              
            
          
          
            
              
                
              
            
          
          
            
              
                
                  
                    
                      
                        
                          
                        
                      
                    
                  
                
              
            
          
          
            
              
              
                
                  
                    
                  
                
              
              
            
          
        
      
      
        
      
      
        
      
      
        
          
          
        
      
      
        
        
          
          
            
          
          
            
          
        
      
      
        Oracle Web Service
        
          
        
      
    
    
  • Clone VM and problem with selection of data store

    Hello

    When I tried to clone a virtual machine that has distributed records in several data stores, I never had the chance to select the store multiple data for the clone, he asks only for the unique data store and discharge all vmkdks to this one, is it possible that I can choose several data stores?  for example: I want to drive D: to E: drive to datastoreC c, datastoreB: diving in datasoreA

    Thank you

    Beatrice

    Hi Alain,

    When you run the clone operation, when you are prompted to select the destination data store, don't you have an Advanced button? If you click on it, you should have access to a menu where you can choose a different destination for each virtual disk.

    Concerning

    Franck

  • Assign an ID to multiple records in bulk by using the checkboxes.

    I have a data block that contains the number of records. There is a check box against each file. and a button below the records.

    I want to assign an id to multiple records whose check box is selected.

    My requirement is when I click on the button under the block, then unique id must be assigned to all the records check box is selected.

    Maybe it is done by means of cursor or loops or both.

    Please, help me in coding of what trigger button.


    Thank you very much.

    Press and hold in the other block (control block) and when pressed to release button

    go_block('block_name');
    first_record;
    IF :check_box = 'Y' THEN--means checked
       :unique_id := 'value';
    END IF;
    if :system.last_record = 'TRUE' then
      eixt;
    else
     next_record;
    end if;
    first_record;
    

    But beware when the checkbox is disabled also.

    I want to update each record in the block but it is not working. below is my pl code behind button.
    

    If it is a block of the base table, you cannot update in the before update trigger?

    Published by: GD on September 9, 2011 23:25

  • Update multiple records at once

    First, thank you very much the people who have helped me out several times now. I put things together and came across another issue of 'beauty' begin as follows. In the previous topics, I had a way to get to an array of automated classification based on the inputs of a fixtures table and some simple calculations. Now, which has been accomplished which resulted in me having to update all the teams by simply clicking a button.

    As you can see in the code below, using a table with every row a form, at the end of the line, there is a button called 'OK' I have to push to update the record according to. A repeat region for all teams in this query shows the ranking of 'new', but is not yet inserted in the League table. Is it possible to have this repeat region without having to push 18 or 20 times a button update? At the end of the table, one (1) button update all records? The primary key is composed like this ' 0000 - u00a "(4 numéros un tiret puis un «u» 1 ou 2 numéros et 1 ou 2 lettres à nouveau)."

    <?php require_once('Connections/connection.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "klassement")) {
      $updateSQL = sprintf("UPDATE klassement SET wedstrijden=%s, overwinning=%s, verlies=%s, gelijkspel=%s, goalsvoor=%s, goalstegen=%s, goalverschil=%s, punten=%s WHERE ploegid=%s",
                           GetSQLValueString($_POST['wedstrijden'], "int"),
                           GetSQLValueString($_POST['overwinning'], "int"),
                           GetSQLValueString($_POST['verlies'], "int"),
                           GetSQLValueString($_POST['gelijkspel'], "int"),
                           GetSQLValueString($_POST['goalsvoor'], "int"),
                           GetSQLValueString($_POST['goalstegen'], "int"),
                           GetSQLValueString($_POST['goalverschil'], "int"),
                           GetSQLValueString($_POST['punten'], "int"),
                           GetSQLValueString($_POST['ploegid'], "text"));

      mysql_select_db($database_koscw, $koscw);
      $Result1 = mysql_query($updateSQL, $koscw) or die(mysql_error());

      $updateGoTo = "klassement-ploegen.php?reeksid=" . $row_klassement['reeksid'] . "";
      if (isset($_SERVER['QUERY_STRING'])) {
        $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
        $updateGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $updateGoTo));
    }

    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    $reeks_klassement = "-1";
    if (isset($_GET['reeksid'])) {
      $reeks_klassement = $_GET['reeksid'];
    }
    mysql_select_db($database_koscw, $koscw);
    $query_klassement = sprintf("select * from klassement where reeksid = %s order by status asc, punten desc, overwinning desc, goalverschil desc", GetSQLValueString($reeks_klassement, "text"));
    $klassement = mysql_query($query_klassement, $koscw) or die(mysql_error());
    $row_klassement = mysql_fetch_assoc($klassement);
    $totalRows_klassement = mysql_num_rows($klassement);

    $id_reeks = "-1";
    if (isset($_GET['reeksid'])) {
      $id_reeks = $_GET['reeksid'];
    }
    mysql_select_db($database_koscw, $koscw);
    $query_reeks = sprintf("select reeksnaam from reeksen where reeksid = %s", GetSQLValueString($id_reeks, "text"));
    $reeks = mysql_query($query_reeks, $koscw) or die(mysql_error());
    $row_reeks = mysql_fetch_assoc($reeks);
    $totalRows_reeks = mysql_num_rows($reeks);

    mysql_select_db($database_koscw, $koscw);
    $query_seizoen = "select * from seizoen";
    $seizoen = mysql_query($query_seizoen, $koscw) or die(mysql_error());
    $row_seizoen = mysql_fetch_assoc($seizoen);
    $totalRows_seizoen = mysql_num_rows($seizoen);

    $huidig=$row_seizoen['huidigseizoen'];
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" media="all" href="../_styles/koscw-admin.css" />
    <title>Klassement <?php echo $row_reeks['reeksnaam']; ?> | Beheerpaneel | 1349</title>
    </head>
    <body>
    <div id="container">
    <h1 class="overzichth1">Klassement <?php echo $row_reeks['reeksnaam']; ?></h1>
    <?php if ($totalRows_klassement > 0) { // Show if recordset not empty ?>
    <table cellpadding="5" cellspacing="0" border="0" id="klassement">
    <tr>
      <td class="klassementsmall bgccc bold"></td>
           <td class="klassementteam bgccc bold">Ploegnaam</td>
           <td class="klassementsmall bgccc bold">+</td>
           <td class="klassementsmall bgccc bold">-</td>
           <td class="klassementsmall bgccc bold">=</td>
          <td class="klassementsmall bgccc bold">#</td>
           <td class="klassementsmall bgccc bold"><img src="../_img/goalsmade.png" alt="Goals +" /></td>
           <td class="klassementsmall bgccc bold"><img src="../_img/goalsagainst.png" alt="Goals -" /></td>
           <td class="klassementsmall bgccc bold"><img src="../_img/goalsdifference.png" alt="Goals &asymp;" /></td>
           <td class="klassementsmall bgccc bold">PTN</td>
          <td class="klassementsmall bgccc"> </td>
    </tr>
    <?php
    $i=0;
    do {
    $i++;
    if($i % 2) { //this means if there is a remainder
         echo "<tr class=\"calendareven\">";
    } else { //if there isn't a remainder we will do the else
         echo "<tr class=\"calendarodd\">";
    }
    ?>
    <td>
    <?php
    $rank += 1;
    echo $rank;
    ?>      </td>
           <td class="klassementteam">
              <?php
            $thuisploeg=$row_klassement ['ploegid'];
              $sql_select_thuisploeg="select ploegnaam from ploegen where ploegid = ('$thuisploeg')";
              $resultset_thuisploeg=mysql_query($sql_select_thuisploeg);
              while ($data_thuisploeg=mysql_fetch_array($resultset_thuisploeg))
              {echo $data_thuisploeg['ploegnaam'] . " ";}?></td>
           <form action="<?php echo $editFormAction; ?>" method="POST" name="klassement">
          <input type="hidden" name="ploegid" value="<?php echo $row_klassement ['ploegid']; ?>" />
           <td>
          <?php
           $tw=$row_klassement['ploegid'];
           $sql_select_tw="SELECT COUNT( * ) AS twin FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND thuisploegid = '$tw' AND thuisploeggoals > bezoekersgoals";
           $resultset_tw=mysql_query($sql_select_tw);
           $data_tw=mysql_fetch_array($resultset_tw);
           $data_tw['twin'];
          
           $uitwin=$row_klassement['ploegid'];
           $sql_select_uitwin="SELECT COUNT( * ) AS awin FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND bezoekersid = '$uitwin' AND thuisploeggoals < bezoekersgoals";
           $resultset_uitwin=mysql_query($sql_select_uitwin);
           $data_uitwin=mysql_fetch_array($resultset_uitwin);
           $data_uitwin['awin'];
          
           $win=($data_tw['twin'])+($data_uitwin['awin']);
           ?>
          <input type="text" name="overwinning" value="<?php echo $win; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
          <?php
           $tv=$row_klassement['ploegid'];
           $sql_select_tv="SELECT COUNT( * ) AS tver FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND thuisploegid = '$tv' AND thuisploeggoals < bezoekersgoals";
           $resultset_tv=mysql_query($sql_select_tv);
           $data_tv=mysql_fetch_array($resultset_tv);
           $data_tv['tver'];
          
           $uitverlies=$row_klassement['ploegid'];
           $sql_select_uitverlies="SELECT COUNT( * ) AS aver FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND bezoekersid = '$uitverlies' AND thuisploeggoals > bezoekersgoals";
           $resultset_uitverlies=mysql_query($sql_select_uitverlies);
           $data_uitverlies=mysql_fetch_array($resultset_uitverlies);
           $data_uitverlies['aver'];
          
           $ver=($data_tv['tver'])+($data_uitverlies['aver']);
           ?>
          <input type="text" name="verlies" value="<?php echo $ver; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
          <?php
           $thuisdraw=$row_klassement['ploegid'];
           $sql_select_thuisdraw="SELECT COUNT( * ) AS tdraw FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND thuisploegid = '$thuisdraw' AND thuisploeggoals = bezoekersgoals";
           $resultset_thuisdraw=mysql_query($sql_select_thuisdraw);
           $data_thuisdraw=mysql_fetch_array($resultset_thuisdraw);
           $data_thuisdraw['tdraw'];
          
           $awaydraw=$row_klassement['ploegid'];
           $sql_select_awaydraw="SELECT COUNT( * ) AS adraw FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND bezoekersid = '$awaydraw' AND thuisploeggoals = bezoekersgoals";
           $resultset_awaydraw=mysql_query($sql_select_awaydraw);
           $data_awaydraw=mysql_fetch_array($resultset_awaydraw);
           $data_awaydraw['adraw'];
          
           $draw=($data_thuisdraw['tdraw'])+($data_awaydraw['adraw']);
           ?>
          <input type="text" name="gelijkspel" value="<?php echo $draw ?>" class="inputscore" readonly="readonly" />
          </td>
          <td>
          <?php $wedstrijden=$win+$ver+$draw; ?>
          <input type="text" name="wedstrijden" value="<?php echo $wedstrijden; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
           <?php
          $tgv=$row_klassement ['ploegid'];
           $sql_select_tgv="SELECT SUM( thuisploeggoals ) AS tgv1 FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND thuisploegid = '$tgv'";
           $resultset_tgv=mysql_query($sql_select_tgv);
           $data_tgv=mysql_fetch_array($resultset_tgv);
           $data_tgv['tgv1'];

          $ugv=$row_klassement ['ploegid'];
           $sql_select_ugv="SELECT SUM( bezoekersgoals ) AS ugv1 FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND bezoekersid = '$ugv'";
           $resultset_ugv=mysql_query($sql_select_ugv);
           $data_ugv=mysql_fetch_array($resultset_ugv);
           $data_ugv['ugv1'];

           $gv=($data_tgv['tgv1'])+($data_ugv['ugv1']);
           ?>
          <input type="text" name="goalsvoor" value="<?php echo $gv; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
           <?php
          $tgt=$row_klassement ['ploegid'];
           $sql_select_tgt="SELECT SUM( thuisploeggoals ) AS tgt1 FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND bezoekersid = '$tgv'";
           $resultset_tgt=mysql_query($sql_select_tgt);
           $data_tgt=mysql_fetch_array($resultset_tgt);
           $data_tgt['tgt1'];

          $ugt=$row_klassement ['ploegid'];
           $sql_select_ugt="SELECT SUM( bezoekersgoals ) AS ugt1 FROM kalender WHERE seizoen = '$huidig' AND speeldag !=0 AND thuisploegid = '$ugv'";
           $resultset_ugt=mysql_query($sql_select_ugt);
           $data_ugt=mysql_fetch_array($resultset_ugt);
           $data_ugt['ugt1'];

           $gt=($data_tgt['tgt1'])+($data_ugt['ugt1']);
           ?>     
          <input type="text" name="goalstegen" value="<?php echo $gt; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
           <?php $goals=$gv-$gt; ?>
          <input type="text" name="goalverschil" value="<?php echo $goals; ?>" class="inputscore" readonly="readonly" />
          </td>
           <td>
           <?php $punten=($win*3)+($draw*1); ?>
          <input type="text" name="punten" value="<?php echo $punten; ?>" class="inputscore" readonly="readonly" />
          </td>
          <td>
          <input type="submit" value="OK" />
          </td>
          <input type="hidden" name="MM_update" value="klassement" />
           </form>
      </tr>
      <?php } while ($row_klassement = mysql_fetch_assoc($klassement)); ?>
    </table>
    <?php } // Show if recordset not empty ?>

    </div>
    </body>
    </html>
    <?php
    mysql_free_result($klassement);

    mysql_free_result($reeks);

    mysql_free_result($seizoen);
    ?>

    Each record is separated, as well as a record can be updated at once, unless you want that all records have the same value.

    To update multiple records in a single operation, you must send the form tabular data. You do this by adding an empty pair of brackets at the end of the name attribute of each entry on the form like this:

     
    

    This translates by $_POST ['ploegid'] which contains a table of all IDS: $_POST ['ploegid'] [0], $_POST ['ploegid'] [1], $_POST ['ploegid'] [2] and so on. All the attributes of the repeat region name need to have added hooks. The following hidden field should be outside of the repeat region and may not have the brackets:

    
    

    You can then use a loop for updating the values like this:

    for ($j = 0, $len = count($_POST['ploegid']); $j < $len; $j++) {  $updateSQL = sprintf("UPDATE klassement SET wedstrijden=%s, overwinning=%s,   verlies=%s, gelijkspel=%s, goalsvoor=%s, goalstegen=%s, goalverschil=%s,   punten=%s WHERE ploegid=%s",                       GetSQLValueString($_POST['wedstrijden'][$j], "int"),                       GetSQLValueString($_POST['overwinning'][$j], "int"),                       GetSQLValueString($_POST['verlies'][$j], "int"),                       GetSQLValueString($_POST['gelijkspel'][$j], "int"),                       GetSQLValueString($_POST['goalsvoor'][$j], "int"),                       GetSQLValueString($_POST['goalstegen'][$j], "int"),                       GetSQLValueString($_POST['goalverschil'][$j], "int"),                       GetSQLValueString($_POST['punten'][$j], "int"),                       GetSQLValueString($_POST['ploegid'][$j], "text"));
    
      mysql_select_db($database_koscw, $koscw);  $Result1 = mysql_query($updateSQL, $koscw) or die(mysql_error());}
    
  • Insert multiple records in a form with checkboxes

    Hello

    I need to insert multiple records in a database of a form using Coldfusion and am stuck - it works correctly when inserting one record at a time. Basically, the user will choose their name of the employee (EmployeeID) in a dynamic list, then several session (open) numbers that represent classes of training.

    When I try and select several check boxes, I get this error:
    "The number of query values and destination fields is not the same."

    The boxes of the open field are not dynamic, as you can see-how use CFLOOP or any other method to allow several checkboxes be selected, and all open documents is entered into the database on a form?

    I used server behaviors Dreamweaver 8 to create the form - which is limiting I know but I'm not a coder. I hope I can add code here to do things correctly function.



    ----APPLICATION CODE------------------------------------------------------------------

    <!-get employee names->
    < cfquery name = "rsDisplayEmployee" datasource = "FormationRH" >
    SELECT *.
    OF tblEmployees
    ORDER BY LastName ASC < / cfquery >
    <!-->-->
    <! - insert Records - >
    < cfset CurrentPage = GetFileFromPath (GetTemplatePath ()) >
    < cfif IsDefined "(FORM. MM_InsertRecord") AND the FORM. MM_InsertRecord EQ 'form1' >
    < cfquery datasource = "FormationRH" >
    INSERT INTO tblEnrollments (open, EmployeeID)
    VALUES)
    < cfif IsDefined "(FORM. Open") AND #FORM. Open # NEQ "" > "".
    #FORM. Open #.
    < cfelse >
    NULL VALUE
    < / cfif >
    ,
    < cfif IsDefined "(FORM. EmployeeID") AND #FORM. EmployeeID # NEQ "" > "".
    #FORM. EmployeeID #.
    < cfelse >
    NULL VALUE
    < / cfif >
    ) < / cfquery >
    < cflocation url = "2.cfm" >
    < / cfif >
    <!-->-->

    --------FORM CODE-----------------------------------------------------------------------

    < form action = "" < cfoutput > #CurrentPage # < / cfoutput > "id = 'form' name ="form"method ="POST">"
    < table width = "100%" border = "0" cellspacing = "0" cellpadding = "4" >
    < b >
    < td width = "100%" > < h2 > < strong > select an employee name < facilities > < / h2 > < table >
    < /tr >
    < b >
    < td > < select name = "EmployeeID" >
    < cfoutput query = "rsDisplayEmployee" >
    < option value = "#rsDisplayEmployee.EmployeeID #" > #rsDisplayEmployee.LastName #, #rsDisplayEmployee.FirstName # < / option >
    < / cfoutput >
    < / select > < table >
    < /tr >
    < /table >
    < h2 > < strong > select training class < facilities > < / h2 >
    < table width = "600" border = "0" cellspacing = "0" cellpadding = "0" >
    < b >
    < td width = "227" valign = "top" > class < table >
    < td width = "373" valign = "top" > < input name = "Open" type = "checkbox" value = "937" / >
    Date < table >
    < /tr >
    < b >
    < td valign = "top" > class < table >
    < td valign = "top" > < label >
    < input name = "Open" type = "checkbox" value = "936" / >
    < / label >
    Date < table >
    < /tr >
    < /table >
    < br / >
    < input type = "submit" name = "Submit" value = 'Sign Up!' / >
    < input type = "hidden" name = "MM_InsertRecord" value = "form" >
    < / make >

    "Add a line" I want to say that, for each of the checkboxes selected in your form, the code will be to insert a new record in the database table. Sorry I probably didn't phrase it very well.

    so, no, the code does not need to wrap around each element. Instead the code examines the form.fieldnames variable (form.fieldnames, which is a list separated by commas of all fields defined in the form, is automatically submitted to each form submission - you don't have to define yourself somehow) and for each selected checkbox will insert a new record in your table with the check box selected and selected value the value of the id of the employee.

  • fetch multiple records form

    How to write a fetch statement that retrieves multiple records and allow users scroll record 1/3,2/3, 3/3... in the form? I'm not using built in the declaration of add\update\fetch

    example: table seller

    number of seq_no (PK);
    vendor_id number;
    date of call_date;
    issue_asked varchar2 (50);

    When I type in the vendor_id, I want to implement the documents associated to the id in the form. I think I might just need a few meter and loop to increase select it in the statement, but I'm not sure how yet or are there any built in can I use under apex? can u help?

    Munshar

    Do you need to be able to update the tables or only the subtable? If it is only the 'CALLS' table you might create a normal report for sellers and a tabular presentation of the calls. Add a link to the seller's report to display the form as a table for this provider.

  • Several box insert as multiple records

    I'm relatively new to ColdFusion. It's the simplicity, as well as Dreamweaver insert/update/delete assistants, have helped build clean enough applications for database insertion, recovery and deletion and display.

    However, I have to be able to insert several selections of boxes as multiple records in a table, and I am running into problems. I guess this sort of thing is the premise of virtually any shopping cart out there, but I can't seem to find any good information on in my 'develop with CFMX manual' or my "Kit of Construction CFMX Web App" book or on the web also. (The only examples for the page of the form or the action page are a static box!)

    The basic premise of what I'm trying to achieve:

    The user is able to select different items in several boxes. (ITEM_ID)
    This selection is associated with the user. (CUSTOMER_ID)
    The selection is associated with a point in time as a year. (INSTANCE_ID)
    These identification numbers that must all be inserted in a 3 column table expecting integers for ITEM_ID CUSTOMER_ID and INSTANCE_ID

    Example of FORM values that would be passed: (147,148,149, 23445, 4) = (3 ITEM_IDs, CUSTOMER_ID and INSTANCE_ID)

    Typical error on presentation to insert action page: Number of columns in reading / writing does not equal the number of values (which is normal, I am gathering several values via checkboxes).

    How can I insert each box is selected as a separate record in the table?

    Such as:
    (147, 23445, 4)
    (148, 23445, 4)
    (149, 23445, 4)

    My Code:

    Form:

    < are method = "post" name = "form2" action = "process_form_action_page.cfm" >

    < table >

    < cfoutput query = "Stored_Procedure1" >

    < b >
    < td > < input type = "checkbox" name = "ITEM_ID" value = "#Stored_Procedure1.ITEM_ID #" > < table >
    #Stored_Procedure1.ITEM_TITLE # < td > < table >
    < /tr >

    < / cfoutput >

    < /table >

    < input type = "hidden" name = 'CUSTOMER_ID' value = '#CUSTOMERS. CUSTOMER_ID #">"
    < input type = "hidden" name = "INSTANCE_ID' value = '#INSTANCE. INSTANCE_ID #">"
    < input type = "submit" value = "Insert record" >

    < / make >


    «"" "Action page:»»"»


    < cfquery datasource = "ORDERS" >

    INSERT INTO PRODUCT_CUSTOMER (ITEM_ID, CUSTOMER_ID, INSTANCE_ID) VALUES)
    < cfif IsDefined "(FORM. ITEM_ID") AND #FORM. NEQ ITEM_ID # "" > "".
    #FORM. ITEM_ID #.
    < cfelse >
    NULL VALUE
    < / cfif >
    ,
    < cfif IsDefined "(FORM. CUSTOMER_ID') AND #FORM. NEQ CUSTOMER_ID # "" > "".
    #FORM. CUSTOMER_ID #.
    < cfelse >
    NULL VALUE
    < / cfif >
    ,
    < cfif IsDefined "(FORM. INSTANCE_ID") AND #FORM. QNE INSTANCE_ID # "" > "".
    #FORM. INSTANCE_ID #.
    < cfelse >
    NULL VALUE
    < / cfif >
    )

    < / cfquery >
    < / cfif >

    Thank you!

    I'm not not to take good advice. If I was a bit too "hard", I'm sorry... but at least I finally got a good response.

    I realized what I wanted anyway. (Sabaidee, yours was the closest answer you to what I later came up with.) Thanks for the effort, I appreciate it. I will certainly implement your logic of to check if the box is checked).

    What I came up with a solution:





    147
    148
    149



    INSERT INTO MyTABLE (CUSTOMER_ID, ITEM_ID, INSTANCE_ID)
    VALUES (' #Form.CUSTOMER_ID # "," #Form.INSTANCE_ID # "," #Checked_ITEM # ")

    If all of the check boxes are selected, the data is inserted as:

    147, 23445, 4
    148, 23445, 4
    149, 23445, 4

    (I realize that there is much more that can be embellished in the form page and the page of the processor).

Maybe you are looking for