Ordering Database Records

Hi all, thanks for reading...
I have table with some simple columns and rows in it. I
wanted to have full control over the order these elements appeared
so created a column named "item_order" which holds a number (1
being highest priority) for each record.
The table looks something like this...(cutting off irrelivant
columns)
ITEM_ID ITEM_ORDER ITEM_PARENT_ID
2 1 1
8 2 1
9 3 1
Numbers not to be read as 211 for example but rather a number
for each column (sorry about the formatting!)
What I basically need to do is design some kind of way that I
can change these orders dynamically with a query.
For example, if i loop through all these records here, each
would be linked and have four options as follows...
Top, Up, Down, Bottom
Top would set the item_order of the selected link in the
output loop to 1 and the rest would have to shift - the same idea
would work for Bottom except giving it the highest number and
shifting the other records the other way (im not worrying about up
and down just yet).
Example output...
<cfoutput query="my_query">
#item_title#
<a
href="index.cfm?item_id=#item_id#&position=top">Top</a>
<a
href="index.cfm?item_id=#item_id#&position=up">Up</a>
<a
href="index.cfm?item_id=#item_id#&position=down">Down</a>
<a
href="index.cfm?item_id=#item_id#&position=bottom">Bottom</a>
</cfoutput>
Each different action would call a different function (cfc)
with a query in it which will do all the necessary stuff to modify
the item_order column depending on the item_id and shift all other
records item_orders accordingly.
I have had a go - please see code attached....and while this
works sometimes and it doesn't throw an error it has
inconsistencies and is a little buggy.
I'm pretty sure this shouldn't be that hard but i'm finding
it very tricky.
Any help or advice would be greatly appreciated. If you don't
understand what I mean or I am being a little confusing please
clarify with me and I'll try again.
Many thanks,
Michael.
PS - This is all so I can then have the desired effect of
explicitly ordering my items for display. Take the following query
for example...
<cfquery name="items" datasource="#request.dsn#"
username="#request.username#" password="#request.password#">
SELECT *
FROM ob_items
WHERE item_parent_id = <cfqueryparam
value="#arguments.item_id#" cfsqltype="cf_sql_integer" />
AND item_deleted = 'No'
ORDER BY item_order ASC
</cfquery>
This would order by the item_order column where my items will
be 1,2,3,4 etc.

Hi,
Thanks for the response, it's nice to get another view from
someone outside of my own head!
I'm a bit confused about this line though in the first
query...
WHERE item_id <> #chosen_item#
In theory, if I am correct, this query will update all the
rows item_order column to the value it currently is + 1 where the
ID is less than or greater than the chosen items ID. But this
doesn't make sense if the only items that need to be modified in
the TOP function are items with the item_order column value less
than the selected items item_order value. Am I making any sense?
E.g. If I have items with orders of 1,2,3,4 and I want to
move the row with item_order 3 to the top then the record with
value of three will need its item order updating to 1 and any items
above it (1 and 2) need to shift up one so 1 becomes 2 and 2
becomes 3....replacing the original 3rd position. So record with
the item_order of 4 in this case isn't touched at all because
moving an item to the top which was already above it should not
affect it.
If you have the time to explain it a little more I'd be
really greatful...I am even surprised someone managed to decipher
what I even said!
Many thanks,
Mikey.

Similar Messages

  • Automatically numbering database records

    I have a database in AW 6 and would like each record numbered so that I can count records. I saw that I can do this for entering new records, but have already set up and imported most data. I would like the numbers not linked to each specific record but just to give me the amount of records I have regardless of what sort order they are in. Am I missing the way to do this?

    Brie Fly's suggestion covers your stated requirement of simply knowing the number of records in the DB.
    If you do want to actually number each record, the process is fairly simple:
    1. Place the records in the order you want them numbered.
    2. Press shift-command-D to open the Define Fields dalogue.
    3. Create a new Serial Number type field, accepting the default values.
    4. Click Done.
    The new field will be added to to open layout (assuming there is room), and will be automatically populated with numbers showing each records position in the current order of records.
    Note: The values are not dynamic. If you delete record 3, the values in all other records will remain unchanged.
    Regards,
    Barry

  • Saving database records in a flat file

    I am trying to save data from relational database into a flat file and then read back records based on the certain criteria.
    What will be a good approach for me? Should I use random access files or sequential files for storing and
    retrieving data or is there some other technique that is more efficient that I can use.
    Thanks

    I don't think that reading database records from a flat file based on certain criteria is a good approach, no matter how you produce the flat file. Using a second database table makes more sense to me, especially since you already have database software available and ready for use.
    (You asked about a "good approach" and then you wanted a technique that was "more efficient". Those two aren't the same thing at all.)

  • How to output database record in .doc format?

    Good day to all of you! I want to output the database records to a formatted .doc document.For example,
    Here are the db records:
    firstname mid lastname age
    ryan g gomez 23
    shiela m vanilla 21
    and the created document will be a .doc file, which will be formatted with image etc...
    +"File for the first record let's say RyanGomez.doc"+
    h4. Company Logo || Company Name
    h4. -------------------------------------------------------------------------------------------------------
    First Name: Ryan Middle Intial:G Last Name:Gomez
    +"and a separate file for the second format.. and so on...til all the records are created"+
    h4. Company Logo || Company Name
    h4. -------------------------------------------------------------------------------------------------------
    First Name:Shiela Middle Intial:A Lastname:Vanilla
    I know that I need Bufferedwriter/reader or printwriter but I'm having a problem on how to format or edit the output ...any help regarding this?
    I have tried using iText but I think it can only output pdf file...I need a doc output file.

    try {
            // Create a statement
            Statement stmt = connection.createStatement();
            // Prepare a statement to insert a record
            String sql = "DELETE FROM my_table WHERE col_string='a string'";
            // Execute the delete statement
            int deleteCount = stmt.executeUpdate(sql);
            // deleteCount contains the number of deleted rows
            // Use a prepared statement to delete
            // Prepare a statement to delete a record
            sql = "DELETE FROM my_table WHERE col_string=?";
            PreparedStatement pstmt = connection.prepareStatement(sql);
            // Set the value
            pstmt.setString(1, "a string");
            deleteCount = pstmt.executeUpdate();
            System.err.println(e.getMessage());

  • What do I need to hook up a turntable directly to the iPhone 5s in order to record vinyl records?

    What do I need in order to hook up a turntable directly to the iPhone 5s in order to record vinyl records?

    A preamplifier with an RIAA equalised input for a turntable, preferably a USB one,

  • Retrieve the Purchase Order Condition Records Table

    Hallo!
    I have found this code right here:
    http://www.sap-basis-abap.com/sapab025.htm
    It is very useful particular for purposes which I need. Please can somebody
    try to fix the error to get it working. There is an internal table missing.
    Regards
    Ilhan
    Retrieve the Purchase Order Condition Records Table
    select * from ekko.
           select * from konv where knumv = ekko-knumv
               "Get all the condition records for the purchase order
           endselect.
    endselect.
    * Get the info record conditions record
    * First declare the record structure for the key
    data: begin of int_konp,
                 txt1(5),
                 lifnr(5),
                 matnr(18),
                 txt2(4),
                 txt3(1),
            end of int_konp.
    clear: konh, konp, int_konp.
    * data for the record key konh-vakey
    int_konp-txt1    = '00000'.
    int_konp-lifnr    = ekko-lifnr+5(5).
    int_konp-matnr = ekpo-matnr(18).
    int_konp-txt2    = 'ALL'.
    int_konp-werks = ekpo-werks.
    int_konp-txt3    = '0'.
    select * from konh where      kschl = 'PB00'            "Conditions (Header)
                                         and datab => p_datum.       "valid from date
          if konh-vakey = int_konp.                                  "Conditions (Item)
                 select single * from konp where knumh = konh-knumh.
                 continue.
          endif.
    endselect.

    Hi flora
    Just get through the sequence .
    see the table fields ...
    1. From EKKO table take an entry which is having pricing conditions.
    Now in the fields list check out for field EKKO-KNUMV(document condition number).
    2.Take this condition number and now goto table KONV.
    Give the document condition number in the field  KONV-KNUMV and execute .
    This will lead to a list of document condition numbers and some other fields .
    3.Now check for field KONV-KNUMH ,KONV-KAWRT(quantity) and note the value KONV-KWERT  .
    (Remember this is at header level).
    This is ur condition record number.
    **comments
    Now from document condition number we got the condition record number (KNUMH).
    4. now since u want the item level tax procedure go to table KONP and give the condition record number and execute .
    This will give u a list of details .
    Now concentrate on KONV-KAWRT (scale quantity) KONP-KBETR(rate) as this table will store “Pricing  per UNIT “ so product of these two will give u the total pricing tax, for a particular condition type say PR00  .
    For that particular condition item .
    Check the pricing procedure .
    See t-code VK13 and check the pricing procedure .
    From me23 check the same PO num select the item and check the pricing conditions applicable .
    Select a particular pricing and goto condition->analysis->analysis pricing  ,
    Better take help of a SD functional consultant in the process.
    regards,
    vijay.

  • Regarding Purchase order info records

    Hi,
    How do I read the text maintained against purchase order info records, transaction ME12. What is the key that I should use for reading the text maintained.
    Regards,
    Vijay

    it may differ from system to system, so i will tell you how i determined this, rather than what i determined.
    In your development or test system, make a change to the text.
    now, use SE16 and look at table STXH. Put todays date in the TDLDATE selection (and your id for TDLUSER, if you want)
    You should see the changes you made, and the keys associated with the texts. you can then use the FM READ_TEXT to get the text...
    Hope this helps

  • The ABAP/4 Open SQL array insert results in duplicate database records

    Hi,
    Iam getting following error :
    The ABAP/4 Open SQL array insert results in duplicate database records.
    Error in ABAP application program.
    The current ABAP program "SAPLV60U" had to be terminated because one of the
    statements could not be executed.
    This is probably due to an error in the ABAP program.
    " Information on where terminated
    The termination occurred in the ABAP program "SAPLV60U" in "VBUK_BEARBEITEN".
    The main program was "SAPMSSY4 ".
    The termination occurred in line 503 of the source code of the (Include)
    program "LV60UF0V"
    of the source code of program "LV60UF0V" (when calling the editor 5030).
    Processing was terminated because the exception "CX_SY_OPEN_SQL_DB" occurred in
    the
    procedure "VBUK_BEARBEITEN" "(FORM)" but was not handled locally, not declared
    in the
    RAISING clause of the procedure.
    The procedure is in the program "SAPLV60U ". Its source code starts in line 469
    of the (Include) program "LV60UF0V "."
    Please assist how to proceed further ..
    Many thanks
    Mujeeb.

    Sorry, THe correct note is 402221.
    Description from the note
    << Please do not post SAP notes - they are copyrighed material >>
    Edited by: Rob Burbank on Feb 22, 2009 3:46 PM

  • Convert the Database records to a standard XML file format?

    Hai,
    i want to convert the Database records to a standard XML file
    format which includes the schema name, table name, field name
    and field value. i am using Oracle 8.1.7. Is there any option
    please help me
    Thanks in advance.

    You could put the files somewhere and I can export them as QuickTime. Or you could find anyone you know who has Director. Or do the 30 day trial download
    Another approach would be to play the DCR in a browser window, and do a screen recording. But that’s unlikely to give the perfect frame rate that you would get by exporting from Director.

  • Using Java Bean in JSP to show database record

    I have links in my Tomcat container that if someone clicks on a specific link it should go to a Record page (Show.jsp) with all the values associated with a record from a database.
    For example if someone clicks on a specific link like this:
    LinkExample
    it would take you to a jsp with database info for someone named Jones and show you his info:
    Lastname = Jones
    Firstname = Mike
    City = San Diego
    I would like to do this using a Java helper class and bean so I dont have any database connection or Java code in my JSP.
    I created Java class file that has Database connection that works with a Java bean. I just dont know how to get the Show.jsp to work with the Java Bean and Java helper class file.
    Here is what I have for Show.jsp and this is the part I have been working on the longest but cant get it to work because it doesnt seem to work with the database:<jsp:useBean id="user" class="num.UserDB"/>
    //do I call getUser(lastname) here and if so how?
    <jsp:setProperty name="user" property="*"/>
    Last Name: <jsp:getProperty name="user" property="lastname"/><BR>
    First Name: <jsp:getProperty name="user" property="firstname"/><BR>
    City: <jsp:getProperty name="user" property="city"/><BR>My Java Helper class that compiles and connects to database:
    package num;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import num.User;
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName...//database connection stuff here
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
            user.setFirstname(results.getString("city"));
         catch(Exception e)          
                   System.out.println("Exception...");               
       return user;
    }My Java Bean that compiles here:
    package num;
    public class User
      private String firstname;
      private String lastname;
    private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, String city)
           this.lastname = lastname;
              this.firstname = firstname;
              this.city = city;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      //more bean methods for all fields here
     

    Sorry if I wasnt specific enough. I have a link that passes a value (field that is passed is called lastname) to a JSP where I want to show record info for that value that is passed.
    My question is how do I show the database record info on Show.jsp for the lastname field value of Jones where I want to use a Java Bean and Database helper class in Show.jsp
    Here is the message I get when I hit the link (LinkExample) and it goes to Show.jsp:
    org.apache.jasper.JasperException: Cannot find any information on property 'lastname' in a bean of type 'num.UserDB'
    .....My UserDB class:
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName("org.gjt.mm.mysql.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dbconnone?user=smitherson&password=abcdefg");
        Statement stmt = conn.createStatement();
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
                         user.city(results.getString("city"));
         catch(Exception e)          
             System.out.println("Exception..." + e);          
       return user;
    }Bean class:
    package num;
    public class User
      private String firstname;
      private String lastname;
      private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, Sting city)
          this.firstname = firstname;
           this.lastname = lastname;
    this.city = city;
      public String getFirstname()
              return firstname;
      public void setFirstname(String firstname)
         this.firstname = firstname;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      public String getCity()
              return city;
      public void setCity(String city)
         this.city = city;
      

  • How to delete a database record by using EJB entity beans

    Hi, All,
    Does anyone know how to use entity bean to delete a database record? I have all the EJB entity beans created, including access beans to each. I can successfully create records, find and update records, however, I haven't find a way to delete records yet.
    Your response is appreciated.
    Cathy

    Please see EJB Forums for continue discussion on this subject.
    Reference titile: "how to delete database record by using CMP entity beans "

  • Internet required in order to record - privacy iss...

    While my girlfriend is watching something online or playing her online games..I have noticed that I am unable to record any programs and instead get an error message.  As soon as she stops using the internet I can record just fine...she starts using it again and I cant record.
    I thought this was very odd so I did a little test and switched off my internet completely and again I was unable to record anything..so I switched my internet back on again and I WAS able to record.
    There is also a noticeable delay from when I press the record button to when I see the recording confirmation message so because the internet is required and because of this confirmation delay it leads me to believe that my box is sending some information through my internet connection to BT of the programs I am recording.
    Is this true??..if it is true then why does BT need to know what I am recording and how do I opt out of the spyware???
    If its not sending any information then why do i need to be connected to the internet in order to record anything..the programs are coming through my ariel and recorded directly to my box so at no point is the internet required so why???

    maxrpg wrote:
    No I never disconnect my vbox or anything.  I seems that when theres lots of internet activity like watching streaming videos online and/or playing MMO games it will not allow recordings but it works fine when activity is low.  I always thought vision and standard BB were seperate and that they didnt impact on eachother?
    Yes but why do my recording schedules need to be stored on BT servers and what does BT do with this information.  surely the box can store my schedule.
    It just seems odd to me and I cant think of any reason why it needs to be stored on a server instead of my box :\
    For the functionality we have now, and for the last 4 years, there is very little point in having this record of the recordings (past and present - you won't be able to delete things either) on their servers. There is some useful functionality that would benefit from it - the most obvious being multi-room, another being remote access (say from your phone) to modify your scheduled recordings. But as we don't have these features there's only one time when this comes in useful - when you do a factory reset which deletes everything on your box. Not being able to make or delete recordings without access to the Vision servers is, at present, a royal pain in the bottom.
    I've never heard of internet usage contention causing the vbox to have no access to the servers. Possibly your hub is faulty. Try rebooting it, or better giving it 15 minutes powered off, or best yet doing a factory reset of the home hub and see if that makes a difference.

  • Layout for editing database record

    Hi!
    I'm trying to make a JPanel display a database record for editing in a nice way, but I'm kinda stuck. Example:
            Id: 10
    First name: Peter
    Last name: Johnson
           Age: 20 and so on. The problem is that I don't know what strategy to use for the layout management, so that it looks good. I use JLabel for all labels and the Id number, since it's not editable, and JTextField s for the other data. I want the labels for the fields right aligned and the textfields left aligned "in their container", so that there is a streight line between the :s. (I hope you understand...)
    Any help appreciated!
    /Jan

    Thanks!
    The missing link was the FlowLayout.RIGHT constant. I guess I hadn't done my homework.
    Thanks for pointing that out!
    /Jan

  • Urgent: How to have a page CONTINUE to check Database Record?

    Hello,
    How to have a page CONTINUE to check Database Record? For example, there's a page which itself will periodically check the database, if there's any new data the page will Popup a new page with those data. My question is how can the page keep checking the database?
    One of the solution(not good) is that there's a hidden frame with a hidden Servlet, it will refresh every x secs and connect database for every refresh, it seems not a good solution. Please suggest some idea. Another way is using applet.
    Someone suggest me to use JMS, I know nothing about it, so is it possible and how,thanks very much
    Thank you.
    Ken

    I don't think JMS is suitable for your solution but I know very little anyway.

  • Order of records in o/p  of select statement

    Hi all
    I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
    circumstances the order of the records of the select statement is different.
    sample select statement which I need to execute
    select emp_no from emplyees where designation = 'programer'
    in one word order of records of in the o/p of a select statement will be unique ?
    (provided same query same, table,)
    can u plz quote the link to get more information
    regards
    Renjith

    Hi,
    YES, you can
    Do Order By Without Using Order By Clause
    in your select statement.
    I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
    Solution 1:
    Select Emp_no
    from Emp
    group by Emp_no;
    the o/p will be in the sorted in the Ascending order.
    Solution 2: ( Only for columns holding Numeric Values )
    Select Emp_No
    From Emp
    Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
    Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
    Note: You Should only use this method on not very large tables coz of performance issue.
    Hope this will solve your problem.
    Any Comment on this, any body.
    Thanks and Regards
    There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem.

Maybe you are looking for

  • Newly Created Infoobjects are not displaying in the RSA1

    Dear Experts, When ever i am trying to create a new Info Object Characterstic/Keyfigure, i am able to create and activate it sucess fully, but when i am trying to see the same in corresponding infoobjects catelog in RSA1 that object is not displaying

  • GL View

    I have done the settings for New GL document splitting.  Item category, field status, profit centre, segment, etc. are made correctly.  Profit Centre/Segment field is kept as a mandatory setting.  No posting is allowed to Dummy Profit Centre also. I

  • Create Swatch and use it to fill a box

    Thanks for taking the time to read my question. I've been trying for some time now to create a swatch from a pattern I've made. I've managed to create the swatch, but it is not available when I open a new document.  Also I don't understand how I'm su

  • Data Types for RadioButtons and PushButtons

    Is there a data type for representing radioButtons and pushButtons in the Oracle tables? If not, what is the alternative to using these controls? null

  • URGENT! Need hel for installing Photoshop Elements to my mac

    Hi, I'm  having this problem since 1 month ago, I bought Photoshop elements 10 but when i try to install it to my MACBook Pro (Version 10.7.4), I can't install it I insert the dvd and everything runs perfectly, it ask for my Adobe ID and then for my