Find the index of a missing row

Hello,
I would like some help in designing this query. For example i have a table with these record.
ID_BOOK | Name | Surname
1               Name1 SurName1
2               Name2 Surname2
3  Name3 Surname3
4   
 Name4 Surname4
6  Name6 Surname6
where ID_BOOk is a primary key
For example the missing row of 5 was previously deleted and i have no information about it. I need to write a query for  the value of the primary key that was deleted by the previous query or if none of the rows werent deleted i want the last row or
at least turn 0. I also need to implement this in LINQ in C# but at least need the logic in SQL. Thank you very much. 

Hello,
This should work for you: Self JOIN on the table over ID_BOOK whereby you add 1 on the right side, then check if rows don't return a right record =>
SELECT SRC.ID_BOOK + 1 AS MissingID
FROM yourTable AS SRC
LEFT JOIN
yourTable AS DST
ON SRC.ID_BOOK = (DST.ID_BOOK + 1)
WHERE DST.ID_BOOK IS NULL
Olaf Helper
[ Blog] [ Xing] [ MVP]

Similar Messages

  • How can I find the index from a specific container?

    How can I find the index from a specific container?
    For example, if I'm traversing through textframes like so (an example, not tested):
    var doc = app.activeDocument;
    var story = doc.pages[0].textFrames[0].parentStory;
    for (var i=0, l=story.textContainers.length; i<l; i++) {
         var textFrame = story.textContainers[i];
         if (textFrame.constructor.name == "TextFrame") {
              var lastPara = textFrame.paragraphs.lastItem();        //How can I find the index of this in relation to the story?
    How can I find the index of "lastPara" in relation to the story rather than the current container?
    I tried:
    var newPara = story.paragraphs[lastPara.index];
    but this results in an invalid object. . .
    alert(newPara.isValid);      //returns false

    The .index property is the character offset. So lastPara will begin at story.characters[lastPara.index].

  • Strings: Finding the index value of the 1st alphabet character

    Hi
    I'm trying to find a way of finding the index position of the 1st alphabetic character i.e. letters from "a" to "z" in a string line.
    I've tried looking at the java doc pages on the String Class which contains methods such "indexOf" but i'm very confused on how this all works??
    Could someone please help me.
    Thanks
    Rahul

    Another way is to use regular expressions:
    import java.util.regex.*;
    class RegExTest {   
        public int indexOfRegEx(String regex , String inString){
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(inString);
            boolean found = m.find();
            return found ? m.start() : -1;
        public static void main(String[] args) {
            RegExTest test = new RegExTest();
            System.out.println(test.indexOfRegEx("[A-Za-z]", "a124321"));
            System.out.println(test.indexOfRegEx("[A-Za-z]", "12A4321"));
            System.out.println(test.indexOfRegEx("\\p{Alpha}", "124321"));
            System.out.println(test.indexOfRegEx("\\p{Alpha}", "124321a"));
    }

  • How do I find the index of a row of a group in a presentation?

    I am using a BPM Object Presentation for this and the code is in PBL. From a method (triggered by an event) I need to find out the current row, the index within a Group. (In this case I am referring to the Group array widget, not a user group.)
    The specific implementation is as follows:
    1. Each row of the group has a button named "Edit Topic"
    2. The user clicks the button
    3. The action for that button calls the method EditTopic()
    4. The method EditTopic() needs to know which row it was triggered from.
    Thanks in advance.

    Hi,
    You can retrieve the zero based value of the row in a Group clicked if you add a method inside of the group (make sure it's inside the group and not in the parent BPM Object).
    The presentation's property for the push button inside the group has to be designated as an "action" (vs submit, save or cancel). Name the method associated with the push button in the group something like "getLineClicked()".
    The method only needs to have this one line of logic:
    lineSelected as Int = orderLines.indexOf(this)
    This will give you the zero based index of the row in the group they picked.
    Hope this helps,
    Dan

  • Difference between open loop and closed loop mode when finding the index on a stepper motor axis.

    I have a test system which uses a PXI-7352 motion controller with a MID-7602 stepper motor drive to position a 200 step/revolution stepper motor with an attached 1000 line encoder.  The MID-7602 is configured for 64 microsteps per step, giving 12,800 microsteps and 4000 encoder counts per revolution.  The system is controlled using LabView 7.1 and NI-Motion 6.13.  To home the motor, I've defined a sequence in MAX which first finds the reverse limit switch and then moves forward to the encoder index pulse.
    When finding its reference in open loop mode, the system its reference at the same microstep each time.  When findings its reference in closed loop mode, the system finds its reference somewhere within about a 20 microstep wide range.
    I hope somebody out there with more experience with this controller can describe the difference between finding the encoder index in open loop mode and finding the encoder index in closed loop mode. 
    Thanks,
    Mark Moss

    Hello Mark,
    I suspect that the behavior you are experiencing has today
    with the resolution difference between your encoder and your
    microstepping.  Let me illustrate with an
    example:
    Example Setup
    Stepper
    Motor
    NI
    Motion Controller
    10
    steps per encoder pulse (Every 10 steps the controller gets an encoder
    pulse, therefore positions 0-9 all appear to be 0 to the controller)
    The
    system has a maximum of 3 pull in moves set
    Open Loop Scenario
    The
    system is commanded to go to position 9.
    The
    controller sends out 9 pulses.
    The
    motor moves to position 9.
    Closed Loop Scenario
    The
    system is commanded to go to position 9.
    The
    controller sends out 9 pulses.
    The
    motor moves to position 9.
    The
    controller checks its position and sees that it is still at position 0
    because it has not received an encoder pulse.
    Because
    the controller thinks it is still at position 0, it sends another 9 pulses
    as its first pull in move.
    The
    motor moves to position 18.
    The
    controller checks its position and sees that it is at position 10 because
    it has only received one encoder pulse.
    Because
    the controller thinks it is still at position 10, it sends1 reverse pulse
    as its second pull in move.
    The
    motor moves to position 17.
    The
    controller checks its position and sees that it is at position 10 because
    it has only received one encoder pulse.
    Because
    the controller thinks it is still at position 10, it sends and additional
    single reverse pulse as its third pull in move.
    The
    motor moves to its final position of 16.
    I believe something similar is happening with your
    application as it looks for the index pulse. 
    Because the controller does not compensate for what it perceives as
    position error in open loop mode, the motor always goes to the same commanded
    position.  In closed loop mode, the motor
    is bouncing around inside the single index encoder pulse trying to find a
    certain position.
    There are several recommendations I can make towards
    correcting this behavior.  These
    recommendations are in order of effectiveness:
    Setup
    your system so that there are more encoder counts per revolution than
    steps per revolution.
    Turn
    off pull-in moves by setting them to 0 in MAX.
    Use an
    open loop configuration.
    Play
    around with the pull in window in MAX.
    Regards,
    Luke H

  • How do I complete uninstalling itunes? when I try installing i get an error message saying it can't find the path ,itunes64.msi missing.

    How do I complete uninstalling itunes? when I try installing i get an error message saying it can't find the path ,itunes64.msi missing

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it, which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    The section Install missing components has advice on breaking down the iTunes installer into the individual .msi files which might prove useful if one component won't install normally.
    tt2

  • How to extract substring from string... how to find the index?

    suppose i have a string like
    "string1 string2 string3 string4 string....stringK...stringN"
    i would like to extract the substring from string4 to stringK-1
    where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
    is there a function to extract the substring from string4 to stringK-1
    or is there a function i can use to determine the index of the end of string4 and the start of stringK?
    thks!

    If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
    If you wanna get real fancy, use the split method of String.

  • Finding the minimum value across multiple rows (not in a single column)

    Hello,
    I am running some ad-hoc SQL to test a website implementation of a spec. The ad-hoc sql gives me a set of date values for a specific widget (called a Task). I need to find the Minimum of either (Task.EndDate + 1 year) or the MAX date from the list
    of other dates. I can easily get all of these dates, and compare them visually, but I'm not sure how to make SQL give me just the single value that I want. In the image below, you can see the results. The blue cell is the value I should get if I were to retrieve
    a single value. 
    select 
    [EndDate+12Mo] = DATEADD(year,1,t.EndDate)
    , [TaskEdit] =  t.EditTS
    , [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
    , [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
    , [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
    , [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
    , [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
    , [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
    , [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner join ContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
    from task t
    where 
    t.tasknumber = 
    '2123.001'
    Thanks!
    Jennifer

    Sounds like this to me
    select CASE WHEN [EndDate+12Mo] < MAX(dt) THEN [EndDate+12Mo] ELSE MAX(dt) END AS YourDateValue
    from
    SELECT [EndDate+12Mo],dt
    from
    select
    [EndDate+12Mo] = DATEADD(year,1,t.EndDate)
    , [TaskEdit] = t.EditTS
    , [ResearchEdit] = (select x.editts from Research x where t.researchid = x.researchid)
    , [DeliverableEdit] = (select max(x.EditTS) from Deliverable x where t.taskid = x.taskid)
    , [RTPEdit] = (select max(x.EditTS) from ResTaskParticipant x where (t.taskid = x.taskid and t.researchid = x.researchid) or (t.researchid = x.researchid and x.TaskID is null) )
    , [RelatedTaskEdit] = (select max(x.EditTS) from Task_Related x where t.taskid = x.Task1ID or t.TaskID = x.Task2ID)
    , [CrosscutEdit] = (select max(x.EditTS) from Task_Crosscut x where t.taskid = x.taskid)
    , [TaskFundingEdit]= (select max(x.EditTS) from TaskFunding x where t.taskID = x.taskID)
    , [ContractFundingEdit]= (select max(x.EditTS) from TaskFunding x inner JOINContractFunding y on x.ContractFundingID = y.ContractFundingID where t.taskID = x.taskID)
    from task t
    where
    t.tasknumber =
    '2123.001'
    )t1
    UNPIVOT(dt FOR cat IN ([TaskEdit]
    , [ResearchEdit]
    , [DeliverableEdit]
    , [RTPEdit]
    , [RelatedTaskEdit]
    , [CrosscutEdit]
    , [TaskFundingEdit]
    , [ContractFundingEdit]))u
    )r
    GROUP BY [EndDate+12Mo]
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to Find the Index of Element in the XMLListCollection

    Hi,
    I have a burning question here, and I wonder if anyone has tried to do this.
    I have an XML file that is read into the xml collection, and for each of the names that appear in the file (pre-declared somewhere else) , I tried to remove the element.
      However, it either gives me -1, if I do trace(slc.getItemIndex(xml.@name).toString()); when they exist, or tell me #3594 as shown in the error below:
    Here is the code:
    private function checkBox_change(event:Event):void{    
               xlc = new XMLListCollection(searchResult..book);  
                   len = searchResult..publisher.length();              
                   for (idx=0;idx<len; idx++) {
                       if (checkBox[idx].selected == false) {                          
                               for each (name in input_name2) {  
                               for each (xml in xlc){
                               if ((xml.@name == checkBox[idx].label) && (xml.@pub == name)){    
        trace(xml.getItemIndex(xml.@name).toString());
        //I get an error that says 3594: getItemIndex is not a recognized method of the dynamic class XML.                            
    Could anyone please give me some pointers on how to remove the desired element? I do know how to use splice.
    Thanks for your help.
    Alice

    Alice you could do something like this
    delete myXML.(@ISBN=="4689997865")
    Sincerely,
    Michael
    El 04/05/2009, a las 11:54, alice_data <[email protected]> escribió:
    >
    Hi,
    >
    I have a burning question here, and I wonder if anyone has tried to 
    do this.
    I have an XML file that is read into the xml collection, and for 
    each of the names that appear in the file (pre-declared somewhere 
    else) , I tried to remove the element.
    >
      However, it either gives me -1, if I do 
    trace(slc.getItemIndex(xml.@name).toString()); when they exist, or 
    tell me #3594 as shown in the error below:
    >
    Here is the code:
    >
    private function checkBox_change(event:Event):void{
               xlc = new XMLListCollection(searchResult..book);
                   len = searchResult..publisher.length();
                   for (idx=0;idx<len; idx++) {
                       if (checkBox[idx].selected == false) {
                               for each (name in input_name2) {
                               for each (xml in xlc){
                               if ((xml.@name == checkBox[idx].label) && 
    (xml.@pub == name)){
        trace(xml.getItemIndex(xml.@name).toString());
        //I get an error that says 3594: getItemIndex is not a 
    recognized method of the dynamic class XML.
    >
    >
    Could anyone please give me some pointers on how to remove the 
    desired element? I do know how to use splice.
    Thanks for your help.
    >
    Alice
    >

  • Anyone having a problem with the latest number software. Docs do not open Invalid. The index .xml file is missing?

    I have been having problems since updating to the latest version of Numbers.
    When I try to open files I am getting an error.
    "The document “'13 Tax Prep .numbers” is invalid.
    The index.xml file is missing."
    Anyone else getting this message? Anyone know how to fix the issue?

    Jeff Shenk wrote:
    Numbers 3.1 can recognize both the new files without the index.xml file and the old ones with it, which it imports to the new format.
    Agreed on that part.  But take it a step further.  If Numbers 3.1 is asked to open an old document that is still in the old Numbers 2 format that relies on an index.xml file but Numbers 3.1 can't find the index.xml file (perhaps the document is corrupted) then how can Numbers 3.1 open the document and interpret it in order to convert it to the new format? My guess is that this a possible trigger for the 'index.xml missing' error message.
    Interesting link here on the new document format.
    SG

  • How to find the worst cluf having indexes? on 10gR2

    If the clustering factor(dba_index.clustering_factor) value is close to number of rows of the related table(dba_table.num_rows) this shows bad clustering_factor(CLUF) where as if CLUF is close to the number of blocks of that related table than this shows good CLUF.
    So how may I find the indexes having the worst CLUF valuse in my database. Looking for an SQL operator which produces this "close to" output;
    create table tdba_indexes nologging parallel 4 pctused 99 pctfree 1 as
    SELECT t2.owner, t2.table_name, index_name, clustering_factor, t2.num_rows, t2.blocks, t2.sample_size
      FROM dba_indexes t1, dba_tables t2
    WHERE clustering_factor > 0
       AND t1.owner NOT IN ('SYS', 'SYSTEM')
       AND t2.owner NOT IN ('SYS', 'SYSTEM')
       and t1.owner = t2.owner
       and t1.table_name = t2.table_name
       AND t2.blocks > 0
    ORDER BY clustering_factor DESC ;
    create table tcluf_bad nologging parallel 4 pctused 99 pctfree 1 as 
    SELECT *
      FROM (SELECT CASE
                      WHEN a_sql_operator_needed_here_for_close_to_determination THEN
                       'BAD'
                      ELSE
                       'NOT SO BAD'
                   END AS "CLUF",
                   abs(clustering_factor / num_rows) ratio1,
                   abs(clustering_factor / blocks) ratio2,
                   t.*
              FROM tdba_indexes t)
    WHERE cluf = 'BAD' ;Thank you.

    John thank you for your comments. You are right, making structural changes on a table(like CTAS with ORDER BY parallel to the bad CLUF indexes' columns sort) may introduce new problems for other queries involved with other indexes.
    This is not a good approach after all. What I am trying is to reduce he high db file sequntial read waits on my CRM database.
    http://www.perfvision.com/wait/db_file_sequential_read.html
    My primary focus must be SQL and Application tuning to reduce the logical i/o amounts of these queries which are the root cause of this wait. But also I saw that these queries have high CLUF values and doing INDEX RANGE SCAN and this kind of a change may also helpful.
    In order to find the root cause queries of this wait I am planning to use this query, can I also have your comments on this;
    SELECT a.sql_text, t.*
      FROM (SELECT tt.*
              FROM (SELECT rownum rn, x.*
                      FROM (SELECT a.sql_text, a.user_io_wait_time, a.executions, a.sql_id
                              FROM v$sqlstats a
                             WHERE user_io_wait_time > 0
                               AND executions > 10
                             ORDER BY a.user_io_wait_time DESC) x) tt
             WHERE rn < 11) a,
           TABLE(dbms_xplan.display_cursor(a.sql_id,
                                           NULL,
                                           'ALL')) t
    WHERE plan_table_output LIKE '%INDEX%RANGE%SCAN%';Best regards.
    Message was edited by:
    antu

  • Get the index of a specific item in a Datagrid

    Is their an easy way to get the index of specific item in a datagrid.  So say my DG holds ten items of type foo.  I need to find the index of foo #8. Remember the foo's may not be in orde 1-8 because of sorting or something. 
    Do I just need to run iterate through the rows and find, which matches the object I am looking for?

    Thats it thanks. DG is getting refreshed so old objects don't match up to new objects so have to do it manually.
    Thx.

  • Key Constraints in the Index Tables

    Hey,
    I am a starter in the Database Application Development.
    I have created few indexes on columns of different tables, and I wanted to look into the ALL_INDEXES and the USER_INDEXES to find the indexes that I created.
    I noticed that there are some primary keys listed in the ALL_INDEXES or USER_INDEXES tables.
    Can somebody tell me why the Primary Keys that are defined on tables are also getting listed in the USER_INDEXES or ALL_INDEXES tables.
    Thanks a Million

    That's very simple.
    To be a primary key a column must verify two conditions:
    1) is not nullable
    2) is unique
    Indexes can be declared unique, hence the simplest way oracle has to create a primary key constraint is to create an authomatuc unique index on it:
    SQL>  create table x (a number);
    Table created.
    SQL> select * from user_indexes where table_name='X';
    no rows selected
    SQL> desc x;
    Name                                                     Null?    Type
    A                                                                 NUMBER
    SQL> alter table x add constraint x_pk primary key (a);
    Table altered.
    SQL> desc x;
    Name                                                     Null?    Type
    A                                                        NOT NULL NUMBER
    SQL> -- A has become NOT NULL
    SQL> select index_name, uniqueness
      2   from user_indexes where table_name='X';
    INDEX_NAME                     UNIQUENES
    X_PK                           UNIQUE
    SQL> -- an authomatic index has been created
    SQL> drop index X_PK;
    drop index X_PK
    ERROR at line 1:
    ORA-02429: cannot drop index used for enforcement of unique/primary key
    SQL> -- You cannot drop it because it enforces the primary key
    SQL> alter table x drop constraint x_pk;
    Table altered.
    SQL> -- but if you drop the primary key...
    SQL> select index_name, uniqueness
      2   from user_indexes where table_name='X';
    no rows selected
    SQL> -- ...the index too is automatically dropped.Max
    http://oracleitalia.wordpress.com

  • Find the warehouse in Cell of system matrix

    I´m trying to find the warehouse code in each row of matrix with the following code:
    oEditText = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("24").Cells.Item(oMatrix.RowCount - 1).Specific);
    in the several sales documents as invoice, quotation... my add-on can get the warehouse code in column 24, in the Sales Order my code return the error: Row - Invalid index  . The index in Sales Order is different?
    Anyone can tell me the best way to find the warehouse code in matrix row?
    thanks in advance.
    Luis Duarte

    U can find the column no of the warehouse column as,
    Dim matMatrix As SAPbouiCOM.Matrix
    Dim txtWhse  As SAPbouiCOM.EditText
    Dim intI,intJ as Integer
    For intI = 1 To matMatrix.RowCount
    For intJ = 1 To matMatrix.Columns.Count
                            If matMatrix.Columns.Item(intJ).Title = "Whse" Then
                                txtWhse = matMatrix.Columns.Item(intJ).Cells.Item(intI).Specific
                            End If
                        Next
    Next
    The column name of the Warehouse column is Whse.U can find it within the matrix itself using the column name as shown above.The variable intJ returns the column no. of warehouse.

  • Why is the panorama tab button missing from my tab bar

    Just downloaded Beta 4 and find the panorama button is missing from the tab bar. Your video showing how to manipulate tabs show the button on the right hand side of the tab bar, on my download it is missing why, also some of the other bars shown in your video are missing to, why??

    You can add it if you want, right-click on a toolbar and select Customize. You can then drag and drop the "Tab Groups" icon from the customize toolbar dialog onto the toolbars. You can use this method to add other icons to the toolbars.

Maybe you are looking for

  • Third Party Apple Loops not being shown in Loop Browser.

    Hey Everyone! I posted this in the GB forum but nobody answered... maybe here someone can shed some light on this issue. I am a quite experienced user of GB, Logic and Soundtrack, and usually I find the workarounds for these kind of problems but I'm

  • Month,year wise

    month,year wise query. Posted: Jan 3, 2012 11:28 AM Edit Reply i have from anf to date parameter if i enter from date 13-jan-2011 and to date is null (upto as on date ) i created matrix format. but i need the how to print the months in matrix column

  • Strange problem with Outlets and Collection View Items

    This is a strange issue. I am using XCode 3.2.2 and I am building a Collection View. To do this I have a non-document based application that uses Core Data. *Collection View Item Class* I created a new class that inherits NSCollectionViewItem and bui

  • Is it possible to execute simple class

    Sir, Is it possible to execute a simple program written in java in jdeveloper. If yes please let me know how to that. I creted a class using class wizard and added the following statement; System.out.println("testing"); I able to compile the program

  • JSTL escapeXml() function not working. . .

    Hi all, I have a problem trying to use the function �escapeXml()� from the functions tag library, my code is below. I have added JSTL1.1, both standard.jar and jstl.jar, to my project. I have placed the fn.tld in the WEB-INF directory and web.xml con