Constraint - at most one record has status 'active' in a table.

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Prod
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
Thank in advance. I have a table like this:
CREATE TABLE FIFAPPS.FS_MST_SUPPLIER
SUPL_CODE VARCHAR2(12 BYTE) NOT NULL,
SUPL_STATUS VARCHAR2(12 BYTE) DEFAULT 'ACTIVE' NOT NULL
How to make constraint such that at most one supl_code has supl_status = 'ACTIVE' in the table.
For example:
-- BELOW IS NOT CORRECT AS THERE ARE TWO RECORDS WITH SUPL_STATUS='ACTIVE'
record 1 : (supl_code = '1',SUPL_STATUS='ACTIVE')
record 2 : (supl_code = '2',SUPL_STATUS='NOT ACTIVE')
record 3 : (supl_code = '3',SUPL_STATUS='ACTIVE')
-- -- BELOW IS CORRECT AS THERE IS ONLY ONE RECORD WITH SUPL_STATUS='ACTIVE'
record 1 : (supl_code = '1',SUPL_STATUS='ACTIVE')
record 2 : (supl_code = '2',SUPL_STATUS='NOT ACTIVE')
record 3 : (supl_code = '3',SUPL_STATUS='NOT ACTIVE')
-- -- BELOW IS CORRECT AS THERE IS NO RECORD WITH SUPL_STATUS='ACTIVE'
record 1 : (supl_code = '1',SUPL_STATUS='NOT ACTIVE')
record 2 : (supl_code = '2',SUPL_STATUS='NOT ACTIVE')
record 3 : (supl_code = '3',SUPL_STATUS='NOT ACTIVE')

You cannot refer other rows in check constraint I feel.Ideally these type of validations should happen from your Front-end.
You can try something like below by adding a virtual column..
SQL> CREATE TABLE FS_MST_SUPPLIER
  2  (
  3  SUPL_CODE VARCHAR2(12 BYTE) NOT NULL,
  4  SUPL_STATUS VARCHAR2(12 BYTE) DEFAULT 'ACTIVE' NOT NULL
  5  );
Table created.
--"Add a virtual column. The ELSE part here should be your primary key in the table
SQL> alter table FS_MST_SUPPLIER add dummy_col as
   (case when upper(supl_status) = 'ACTIVE' then 'ACTIVE' else supl_code end);
Table altered.
--"Add a unique constraint on the virtual column.."
SQL> alter table FS_MST_SUPPLIER add constraint cons1 unique(dummy_col);
Table altered.
SQL> insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(1,'ACTIVE');
1 row created.
SQL> insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(2,'ACTIVE');
insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(2,'ACTIVE')
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.CONS1) violated
SQL> insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(2,'INACTIVE');
1 row created.
SQL> insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(3,'INACTIVE');
1 row created.
SQL> update FS_MST_SUPPLIER set supl_status = 'INACTIVE';
3 rows updated.
SQL> insert into FS_MST_SUPPLIER(SUPL_CODE,SUPL_STATUS) values(5,'ACTIVE');
1 row created.
{code}
Edited by: jeneesh on Oct 17, 2012 3:40 PM
I did not have to use virtual columns or unique function index for any table in my career...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • One material has two entries in DGTMD table

    Hello Experts,
    I found very strange phenomenon in our production system. There were two or sometimes more than two entries for one material one was showing as Dangerous and other as non dangerous. I mean in DGTMD table in DGNHM field is X for one entry and blank for other entry of the same material. I think this is the cause of previous issues which I posted where same material was shown as Dangerous and non dangerous for same regulation.
    My question to you is what is the resolution for this if this is the cause. How to get this data corrected?

    Hi Devdatt,
    just as an addition to what Pietro answered:
    the concept of DGTMD is to be able to have one valid entry for each relevant regulation for each material:
    - you might have several entries for one regulation in case of different time ranges
    - you might have several entries for different regulations
    The key is not the material number. Please check if the entries you are mentioning are
    - regarding the same regulation and
    - the same time range.
    Best regards,
    Christoph

  • I am getting only one record from table data

    Hi Experts,
    I am using interacive forms to bring the table data i used  GET_STATIC_ATTRIBUTES_TABLE
    method. initially the table is empty when i fill some records more than one it is giving me only one record.
    where as i fill the table in wddoinit more than one record and try to retreived it, showing all the records more than one. waht is the reason.. if i fill manually why it is not bringing all the reocrds.
    i have used the cardinatly as follows
    1. parent node(no tables/structure used)
    Dictionary structure       empty not used
    Cardinality 1..1
    Selection 0..1
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    2. table node(i used table type)
    Dictionary structure    SFLIGHT_LIGHT
    Cardinality 1..n
    Selection 0..n
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    Pleae help me out...
    Thanks,
    Mahesh.Gattu

    hi,
    Use the following code for making the rows editable for a table UI element.
      DATA lo_nd_cn_try TYPE REF TO if_wd_context_node.
      DATA lo_el_cn_try TYPE REF TO if_wd_context_element.
      DATA ls_cn_try TYPE wd_this->element_cn_try.
      DATA ls_cn_try1 TYPE wd_this->elements_cn_try.
    navigate from <CONTEXT> to <CN_TRY> via lead selection
      lo_nd_cn_try = wd_context->get_child_node( name = wd_this->wdctx_cn_try ).
    do 5 times.                       
    clear ls_cn_try.
    append ls_cn_try to ls_cn_try1.
    lo_nd_cn_try->bind_table( ls_cn_try1 ).
    enddo.
    ->  cn_try is the node which is binded with the Table UI element.
    What all this is called as initialization of table. This code will make 5 rows editable, If u want more rows editable then run the loop according to the requirement.
    U can write this code in the WDDOINIT.
    Thanks,
    Pankaj Aggarwal.

  • Thank you for your service.   I was most disappointed to find, however, that the letters I really wanted (Adobe Garamond Alternate Caps) is not in this collection and indeed, one now has to use another fancy designing program to construct those letters. I

    Thank you for your service.
    I was most disappointed to find, however, that the letters I really wanted (Adobe Garamond Alternate Caps) is not in this collection and indeed, one now has to use another fancy designing program to construct those letters. I can’t afford to buy Photoshop just to construct two special capital letters. I’ve used the B and M in my logo for Balquhidder Music for years - but from jpgs - and I was hoping to have more flexibility in the future. I spent $169 to make sure I am in compliance. But I didn’t get anything of use to me.
    I can’t understand why those Alternate Caps are not part of this - or any other package. I thought Adobe was capable of amazing things.
    I assume I am whistling in the dark. So have a nice day.

    Actually, when Adobe moved from Type 1 fonts to OpenType CFF fonts, all the so-called “expert typefaces” were consolidated into the base fonts. In other words Adobe Garamond Pro Regular not only has the Western Latin characters of the original Type 1 version of Adobe Garamond, but also has alternate Latin capitals (with titling, titling floating accents, and stylistic alternates), alternate Latin lowercase (swash and superiors), Latin small capitals (alphabetic and floating accents), ligatures, multiple numeric forms (including lining tabular, lining proportional, oldstyle tabular, oldstyle proportional, superscripts, scientific inferior, numerator, denominator forms, fractions, mathematical operators, etc.) plus a raft of other special symbols.
    OpenType fonts are Unicode-based and allow for more than the 256 characters in Type 1 fonts which required multiple typefaces all with mappings to a standard keyboard to accommodate all these glyphs.
    Thus, hopefully your disappointment will turn to joy.
    To assist you in understanding OpenType fonts and to show you what is in the current Adobe Garamond fonts, I have attached a few PDF files for your perusal.
    Let us know if you have any questions.
               - Dov

  • Help, I paid but account has not activated. Talk to tech, someone was suppose to get back to me but no one has. What do I do-massively frustrated

    Help, I paid but account has not activated. Talk to tech, someone was suppose to get back to me but no one has. What do I do…massively frustrated

    Check your account page to see if your subscription is listed https://www.adobe.com/account.html
    Some general information for a Cloud subscription
    Log out of your Cloud account... Restart your computer... Log in to your paid Cloud account
    -Sign in help http://helpx.adobe.com/x-productkb/policy-pricing/account-password-sign-faq.html

  • DB Constraint for one record in a table

    Hi I have some config tables where the rule is only one record should be in the table. How can I make a constraint in the database to enforce that only X number of records can be inserted? In this case x=1 :)
    BR
    Tim

    Use the UNIQUE constraint on this field :
    SQL> create table t (x number UNIQUE) ;
    Table created.
    SQL> insert into t values (1) ;
    1 row created.
    SQL> insert into t values (1) ;
    insert into t values (1)
    ERROR at line 1:
    ORA-00001: unique constraint (SYSTEM.SYS_C001808) violated
    U can add this constraint to a field with the ALTER TABLE ADD CONSTRAINT command.
    Fred

  • Start recording video AFTER touch block has been activated - is it possible?

    So I'm in the camera app, I've enabled touch block. But i can only take pictures, either with the hardware camera button or the volume rockers. How do i engage the video recording function AFTER touch block has been activated?

    That seems strange since i can take pictures after having enabled touch block. As it is now i have to edit out the first seconds if I want to film underwater. Very unnecessary

  • Challenge involving creating a file on GUI & seeing one record at a time...

    Hi,
    If anyone can help me with this project I'd be most appreciative. I'll try and explain the problem the best I can. I'm adding students to a database at a university they're either a Graduate or an Undergraduate. I'm taking in first, lastname's, ssn, & ACT/SAT/GMAT test results. I have a GUI called StudentRecord that has all the JTextFields, JButton's, etc. I'm also writing it to a .txt file called StudentDA. For this I used a BufferedFile reader.
    What I really need is on my StudentRecord when I click the display button I want it to show one record at a time in another JFrame. This other JFrame I named it display. I'm trying to create an instance of JFrame inside of the actionPerformed for StudentRecord but when I click display nothing happens.
    I adding the students with a vector that I'm calling v. I want the Display to read from the .txt file and display one at a time hence next, and previous. I'm going to post the tidbit of relevant code. If anyone can help me you'd be my hero for the day for all time I've tried to get this to work.
    Here's the StudentRecord (GUI) display part:
          public void actionPerformed( ActionEvent event )
         try {
              Display d = new Display(StudentDA.v);
             }//end try
            //catch right here no problems with this..Here's the DataAccess part:
    public class StudentDA{
      static Vector v = new Vector();;
      static String pathName = "a:/Final Project/test1.txt";
      static File studentFile = new File(pathName);
      static String status;
      public StudentDA() {}
      public static void initialize() {
        if (studentFile.exists() && studentFile.length() !=0) {
         try{
          BufferedReader in = new BufferedReader(new
          FileReader(studentFile) );
          do{
             status = in.readLine();
              if(status.equals ("uGrad")) {
                uGrad u = new uGrad();
                u.setFName(in.readLine() );
                u.setLName(in.readLine() );
                u.setssNum(Integer.parseInt(in.readLine()) );
                u.setACT(Integer.parseInt(in.readLine() ));
                v.add(u);
                System.out.println(u + "inside ugrad");
              }//end if uGrad
              else{
                if(status.equals("Grad")) {
                //same process as uGrad
                v.add(g);
              }//end else Grad
          }while (status != null);
        }//end try statement
        catch (Exception e) {
          }//end catch
        }//end if there's something there
      }//end method initialize
      //creating the terminate method
      public static void terminate() {
        try{
          PrintStream out = new PrintStream ( new
          FileOutputStream (studentFile) );
          for (int i = 0; i < v.size(); i++) {
            Student s = (Student) v.elementAt(i);
            String p = s.printRecord();
            StringTokenizer rt = new StringTokenizer(p, "\t");
            while (rt.hasMoreTokens() ) {
              out.println(rt.nextToken() );
              }//end while
          }//end for loop
        }//end try loop
        catch (Exception e){
        }//end catch
      }//end terminate
    public static void add(Student s){// throws DuplicateException{
              boolean duplicate = false;
              for(int i = 0; i < v.size(); i++){
                   if(s.getssNum() == ((Student)(v.elementAt(i))).getssNum()){
                        duplicate = true;
                        break;
                   if(duplicate){
                        throw new DuplicateException("Student Already Exists");
                   else{
                        v.add(s);
    }//end add method
    }//end classHere's the display class:
    public class Display extends JFrame {
         private JButton Next, Previous;
         private JTextField statusField, firstField, lastField, socialField, advPlacementField, actField;
         private JLabel statusLabel, firstLabel, lastLabel, socialLabel, advPlacementLabel, actLabel;
         private JPanel fieldPanel, buttonsPanel;
         private JTextArea displayArea;
         static int count = 0;
         static String status;
         public Display(){}
    public Display(Vector v){
         //setting up the GUI components for the display class here
         //JTextAreas & JLabels
         buttonsPanel = new JPanel();
         buttonsPanel.setLayout(new GridLayout(1,2));
        Next = new JButton("Next");
        buttonsPanel.add(Next);
        Next.addActionListener(
        new ActionListener() {
          public void actionPerformed( ActionEvent event )
              //try to catch display errors
           try {
                        count++;
                     displayData(count);
                     //displayData();
          }//end try
              catch {
             }//end catch
          } // end actionPerformed
        } // end anonymous inner class
        ); // end call to addActionListener
        buttonsPanel.add(Next);
        Previous = new JButton("Previous");
        buttonsPanel.add(Previous);
        Previous.addActionListener(
        new ActionListener() {
          public void actionPerformed( ActionEvent event )
              //try to catch display errors
              try {
                   count--;
                   displayData(count);
                   //displayData();
             }//end try
              catch {
             }//end catch
          } // end actionPerformed
        } // end anonymous inner class
        ); // end call to addActionListener
    }//end display() constructor
    public void displayData(int count) {
         StudentDA.initialize();
           if (status.equals ("uGrad")) {
           //these are all part of the StudentRecord GUI not Display GUI
                fieldPanel.setVisible(true);
                buttonsPanel.setVisible(true);
                actLabel.setVisible(true);
                actField.setVisible(true);
                advPlacementLabel.setVisible(false);
                advPlacementLabel.setVisible(false);
           }//end if
           else {
                if(status.equals ("Grad")) {
                 fieldPanel.setVisible(true);
                 buttonsPanel.setVisible(true);
                 actLabel.setVisible(false);
                 actField.setVisible(false);
                 advPlacementLabel.setVisible(true);
                 advPlacementLabel.setVisible(true);
                  }//end if
           }//end else
    }//end method displayData()
    public static void main ( String args[] )
        Display application = new Display();
        application.addWindowListener(
              new WindowAdapter(){
                   public void windowClosing( WindowEvent e)
                        System.exit(0);
        application.setSize( 300, 200);
        application.setVisible( true );
    };//end main
    }//end class Display{}I know this is long but if anyone can help I'd greatly appreciate it. Please ask me if you need me to clarify something, I tried to not make it way too long. --rockbottom01
         

    I'm not really too sure what it is that you are after, but here is some code, that loads up an array with each line of a .txt file, then displays them. I hope you can make use of a least some of it.
    just ask if you don't understand any of the code.
    String array[];
    int i;
    public Test() {
              readFile("file.txt");
              i = 0;
              nextEntry();
         public void nextEntry() {
              Display display = new Display();
              display.show();
         class Display extends JFrame implements ActionListener {
              JLabel label1;
              JButton button;
              public Display() {
                   label1 = new JLabel(array);
                   button = new JButton("OK");
                   getContentPane().setLayout(new FlowLayout());
                   getContentPane().add(label1);
                   getContentPane().add(button);
                   button.addActionListener(this);
              public void actionPerformed(ActionEvent e) {
                   setVisible(false);
                   i++;
                   if(i < array.length) {
                        nextEntry();
         public void readFile(String fileName) {
              String s, s2 = "";
              int lineCount = 0;
              BufferedReader in;
              try {
                   in = new BufferedReader(new FileReader(fileName));
                   while((s = in.readLine()) != null) {
                        lineCount++;
                   array = new String[lineCount];
                   in.close();
                   in = new BufferedReader(new FileReader(fileName));
                   int j = 0;
                   while((s = in.readLine()) != null) {
                        array[j] = s;
                        j++;
              catch(IOException e) {
                   System.out.println("Error");

  • Functionality of OM statuses Active, Planned Submitted Approved & Rejected

    Hi gurus,
    I want to understand the functionality & concept of the statuses in Tx PO13, PO10 etc
    We see
    1.Active
    2.Planned
    3.Submitted
    4.Approved
    5.Rejected
    my question is regarding a requirement.
    We need if some object is created that should be submitted for approval and in  this case e-mails shud be triggered for approval to superiors. Once that is approved the created object shud exist as a valid object in system, otherwise should exist in system but not as an active object and cannot not be used for assigning holders. I mean should not be a valid object.
    I want to know if these statuses will help doing it with work-flows and can we restrict the user to use only one of the five statuses..
    Pls advise ...
    Regards,
    Anil Kumar

    Hi,
    Status identifies the current standing that an object or infotype record has within an organizational plan. Status also affects the type of editing you can do. There are five statuses available:
    Active
    Planned
    Submitted
    Approved
    Rejected
    Objects with different status can appear in the same plan version. The active objects could represent current operations at your firm, and the planned objects could represent changes you plan to make, for example, adding a new department or new position.
    Use
    You must assign a status to every object and infotype record you create. However, you do not need to use all the statuses. Many users choose only to use active status.
    How you apply status to objects and infotype records in Organizational Management, depends on the method you use to maintain an organizational plan u2013 Detail Maintenance, Simple Maintenance, or Structural Graphics.
    Status attributes:
    Active
    Indicates that an object is currently operable. You have unrestricted activities u2013 you can create, change, display, delimit, delete and list when using active objects.
    Planned
    Indicates that an object is proposed or anticipated, but not currently operable. You can create, change, display, delimit, delete and list when using planned objects.
    Submitted
    Indicates that an object has been submitted for review and subsequent approval/rejection. You cannot create objects with submitted status. Nor can you make changes.
    Approved
    Indicates that an object, previously sumitted for review, is accepted or authorized. By changing the status to active, you can edit the object (create, change, display, delimit, delete and list).
    Rejected
    Indicates that an object is rejected or turned down. You can only display objects with rejected status. However, you can change the status to planned so that you can work with the object again.
    There are two ways you can change the status applied to objects and infotype records, in Organizational Plan:
    Run the report RHAKTI00 (Change Object Status) for selected objects or infotype records
    Change the status of objects and infotype records one at a time in Detail Maintenance
    It is not possible to change the status of objects or infotype records in Structural Graphics or Simple Maintenance.
    For workflow related intergration go through this link
    http://help.sap.com/erp2005_ehp_03/helpdata/EN/bb/bdb86d575911d189240000e8323d3a/frameset.htm
    thanks & Regards
    Pallavi

  • I purchased an ipad from a dealer on ebay with a 9 month warranty still on it.  I set it up and decided to return it and buy the new Ipad instead. How can I be sure I didn't activate the warranty, or deactivate if it has been activated?

    I purchased an ipad from a dealer on ebay with a 9 month warranty still on it.  I set it up and decided to return it and buy the new Ipad instead. How can I be sure I didn't activate the warranty, or deactivate if it has been activated?

    Sorry, I can't tell what it is you're trying to ask. What does the warranty have to do with your intention to return the iPad (to whomever) and get another one?
    There's no way to deactivate a warranty.
    The warranty transfers with the machine, has nothing to do with the owner.
    Look around in the Support pages, you can figure out a way to type in your serial number and see what your current warranty status is.

  • View for active Incidents related to WI (Problem) with status (Active) works but can't be changed.

    Hi,
    I wanted to create a view of Incidents which are linked to a Problem (any problem).
    I did a quick test using the Incident (advanced) class, selected to display Incidents with status Active and [Work Item] Is Related To Work Item and status for Problem with the status Active.
    At this first test I didn't bother to select any specific columns to display but just went with the pre-selected ( Description, Display Name, Display Name) and it worked. 
    I got a list of expected Incidents in the view but having the Description column made it quite useless.
    So, when I try to select the columns I find useful it will not update and it returns a No items found message instead.
    (image removed due to limitations)
    It is of course possible to group by one of the Display Name fields and collapse to get a more workable view but it still lacks a lot of good information. One would like to include ID, title, Created date,
    date modified, Display Name for Affected User and Assigned to user, and a few others.
    I was just a bit stumped as to why this fails when changing the columns on a view that obviously is possible to create.
    Thanks in advance,
    Daniel

    Consider using the Advanced View Editor( or
    the free edition), since it has much more robust criteria and column editing capabilities. 

  • How to update more than one records at one time

    hello guys..
    how to update a few records (more than one) with different
    IDs at the same time? i tried to make a query like this (see
    below), but only one record (more than one data in the same
    field)has been updated.
    <cfquery name="rec" datasource="DatKoku">
    select *
    from tbl_pilih
    where id_pel = '#form.idpel#'
    </cfquery>
    <cfquery name="updtrecord" datasource="DatKoku">
    update tbl_pilih
    set
    kptsn = '#form.suk_pil#',
    trkh_kptsn =
    '#Dateformat(TodayDate,"dd/mm/yy")#|#TimeFormat(Now(),"hh:mm:ss
    tt")#'
    where id_pel = '#rec.id_pel#'
    </cfquery>
    <cfquery name="outputrecord" datasource="DatKoku">
    select *
    from tbl_pilih
    where id_pel = '#form.idpel#'
    </cfquery>

    Take the query,
    <cfquery name="rec" datasource="DatKoku">
    select *
    from tbl_pilih
    where id_pel = '#form.idpel#'
    </cfquery>
    If every row in the table has a distinct id_pel, then what
    you ask is actually an impossible question. It will have no answer.
    Distinct IDs imply that the resultset will contain
    at most one distinct value of id_pel. That means, there can
    be at most one row that satisfies the condition,
    where id_pel = '#rec.id_pel#' in the update query. That in
    turn means the update query can update at most one row at a time.
    If, however, the resultset of
    rec consists of multiple rows, it will mean that there are
    multiple rows in the table that have the same
    id_pel . Then, your update query,
    updtrecord, should update all the rows that share that value
    of id_pel.

  • How Can I Have Totals On Only One Record?

    Hi.  I don't have a clue where to start with my query.  I thought I had it, but turns one I'm missing something.
    I have a master table with three detail tables. In the detail tables, it is possible to have multiple records.  In one of the detail tables, I'd like to have a result record for each one present.  For the other two tables, I just want a single
    summation.  I'm seeing the summation on each record and that is throwing my report totals off.
    I have "work order history" as my master.  I have "equipment" as my detail.  For each work order, I want a record that shows the equipment number within the equipment table.  I have "labor" as a detail. 
    I simply need a sum of the total cost.  And I have parts as detail, I need a sum of the cost of parts.
    I'm hoping to see something like this in my result set but I don't have a clue how to do it.
    work order number       equipment number       cost of parts    cost of labor
    20                                   5                                 
    $15                 $100
    20                                   6                                
    $0                    $0
    20                                   7                                
    $0                    $0
            SELECT SUMLABOR.*, SUMPARTS.PARTSTOTAL, DMH.EQUIPNO, DMH.EQUIPNAME, DM.DATEISSUED, DM.DATEREQ, DM.DESCRIPT, DM.COSTCENTER, DM.USER0, DM.USER1, DM.USER2, DM.USER3, DM.USER4, DM.USER5, DM.USER6, DM.USER7, DM.JOBNO, DM.REQUESTNO,
    DM.REQUESTBY,
                                     DM.PRIORITY, DM.DATECOMPLETED, DM.MAINTCODE, DM.SHIFT, DM.WORKTYPE, DM.ESTDNTIME, DM.DOWNTIME, DM.DISTRIBCOSTS,
    DM.TOEMAIL, DM.BATCHASSIGNEMPNAME, DM.STATUS, DM.DATESTART, DM.TIMESTART,
                                     DM.TIMEREQ, DM.TIMEISSUED, DM.DATECLOSED, DM.TIMECLOSED, DM.PHONE, DM.EMAIL, DM.SRFROM, DM.TIMECOMPLETED,
    DM.LOGINNAME, DMH.DAILYRUNTIME, DMH.RUNTIME, DMH.LOCATION, DMH.WARDATE, DMH.UNITS,
                                     DMH.VENCODE, DMH.VENNAME, DM.FROMALARM, DM.DMHID FROM
              SELECT DM.DMHID, DM.WONO AS WONUMBER, SUM(la.labortotal) AS LABORTOTAL FROM DMHISTORY DM
              LEFT OUTER JOIN LABORHD LA ON LA.DMHID = DM.DMHID
              GROUP BY DM.WONO, DM.DMHID
            ) SUMLABOR
            INNER JOIN DMHISTORY DM ON DM.DMHID = SUMLABOR.DMHID
            LEFT OUTER JOIN
              SELECT DM.DMHID, SUM(PARTS.QTYALLOC * PARTS.UNITCOST) AS PARTSTOTAL FROM DMHISTORY DM
              LEFT OUTER JOIN PARTSHD PARTS ON PARTS.DMHID = DM.DMHID
              GROUP BY DM.WONO, DM.DMHID
            ) SUMPARTS ON SUMPARTS.DMHID = DM.DMHID
            LEFT OUTER JOIN DMHEQUIP DMH ON DMH.DMHID = DM.DMHID
    With the query above, I'm seeing this instead
    work order number       equipment number       cost of parts    cost of labor
    20                                   5                                 
    $15                 $100
    20                                   6                                
    $15                  $100
    20                                   7                                
    $15                  $100
    Basically my totals end up doubled or tripled with the current query structure. I only want them on the first record.  And it is possible that no equipment records exist at all and in that case I need a null for the equipment number but need totals
    from the labor and parts tables.
    Any help will be appreciated!  :)  Thanks!
    Debbie Erickson

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You are not even
    close! Temporal data should use ISO-8601 formats. Code should be in Standard SQL AS much AS possible and not local dialect. 
    This is minimal polite behavior ON SQL forums. 
    >> I have a master table with three detail tables. In the detail tables, it is possible to have multiple records [sic]. In one of the detail tables, I'd like to have a result record [sic] for each one present. For the other two tables, I just want a single
    summation. I'm seeing the summation ON each record [sic] and that is throwing my report totals off. <<
    So wrong! The terms master and detail are not RDBMS; that is COBOL and network database terms. I see you are still using punch cards with only uppercase letters. 
    Rows are not records! TOTALLY DIFFERENT CONCEPT! The rows in a table all have the same structure; this is the nature of a set. 
    I see a repeated group users in violation of 1NF. Date used AS an attribute instead of an attribute property. More LEFT OUTER JOINs in one query than I use in entire applications. Think about “DM.dateclosed, DM.timeclosed” as a design flaw. Why use two columns
    for one measuremetnt? This error is called attribute splitting and it violates ISO-11179 rules. An SQL programmer would have a single data element: “DM.closure_timestamp” instead. 
    >> I have "work order history" as my master. I have "equipment" as my detail. <<
    Did you mean referenced and referencing table? Where is the DRI between them? 
    But we have no DDL, so it is probably worse. 
    >> I'm hoping to see something like this in my result set but I don't have a clue how to do it. <<
    Yep! Your whole approach is wrong. Can you throw this out and do it right or do you nee to update your resume and move back to a COBOL shop?  We can probably kludge it, but performance and data integrity will be awful. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to get Most current record in the reporting

    Hi All,
    I have reporting requiremnt  like to get the most recent record.
    Please see the below example we have 3 records but with 2 different sales represtentatives assigened to the same document.but i need to get most recently assigned sales representative record  that is number 2(10726056 and status open).
    Now i am geeting the 2 open records .Need to get only one.we do not have any other difference in the records to keep track of the sales representatives assignment to get the new sales rep id other than request id.
    Can any one tell me  most rcurrent data varibles under the request id do.Will it solves my issues o r any other ideas please welcome.
    Customer No    Sales rep    Doc number    Status     Request id
    0000613086    10726056    9000783660       C            REQU_1
    0000613086    10726056    9000783660       O            REQU_1
    0000613086    10182679    9000783660       O            REQU_2

    Hi Sirisha,
    it seems to be a problem of the kind "exception aggregation" , but let me say it can result in a very complex solution.
    What about using a Virtual Infoprovider with servicecs to solve the issue?
    You should create an additional InfoCube that reads form the basic one (where you have data) and then you should "delete" invalid records considering the request number.
    By the way time stamp seems to be the easier solution.
    Hope it helps
    GFV

  • Select "most recent" records in abap

    Hi
    how can I select the most recent records in a table by using the abap select statement.
    Example: The 100 rows with the "highest" (most recent) sequence-numbers in a table with documents.
    somehow like this:
        SELECT "most recent" * FROM draw
        INTO TABLE gt_doklist
        UP TO 100 ROWS
        where ...
    Has anybody an idea?
    Thanks in advance,
    Willi

    Actually I believe that all the answers are wrong.
    I believe that there will never be a single statement. If you need to determine the last 100 records for a special user you first need to determine the highest document number.
    this can be done by
    select max( document_number ) into document_number from table where username = username.
    Any descending sorting order or group by etc. will never make sure that you get the last one. For a simple reason What should the select statement look like that makes sure (in combination of any cursor applied)? Its impossible!
    If you now need the latest 100 records for a single user its the same problem like buffered number ranges. There is no way to perform that task because there is no database routine or sql statement to do so. And 1.5 million records are too much to try out or select everything.
    You could do an assumption that the last 100 for that user have been posted during the last 1000 or last 10.000 records, select them and filter out.
    Alternative you can perform the following select statement for 100 times. Using an index on document number and user might not be such a performance killer if its only done for one user during his online dynpro process:
    data: max_number type char10.
    select max( documentnumber ) into max_number from table
      where username = username into [structure].
    max_number = max_number + 1.
    do 100 times
    select max( documentnumber ) from table intomax_number
      where username = username and docnumber lt max_docnumber.
    select * from [db_table] into [structure] where docnumber = max_number.
    append [structure] to [table].
    enddo.
    Of course that just draft coding... apply if statements and so on...
    Even though its pretty poor, its the only way to do. Any select statement will never garantee what records you will get if you do not restrict accordingly and if the restriction has to be made on document number, but if there is no way to get the max_number - [100 last records of this user], there is no solution using one statement.
    Thats it.
    Edited by: Rob Burbank on Feb 25, 2010 8:52 AM

Maybe you are looking for