Results 1 to 2 of 2

Thread: from1 to nn access query

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,743

    from1 to nn access query

    I just have an ADO connection opned as CON.

    I a table MYtable have many many records, similar 3.400

    In my table have a filed named NR

    I need a query to update into the filed NR from 1 to 3.400... started from the first record.

    similar:

    1
    2
    3
    4
    ...
    3400

    tath is all.
    Tks

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,990

    Re: from1 to nn access query

    Code:
    SELECT
        (SELECT COUNT(T1.NR)+1 FROM MyTable As T1 WHERE T1.NR<T2.NR) AS NewNR,
        T2.ID, T2.NR, T2.Description /*Other Fields*/
    FROM MyTable AS T2 
    ORDER BY T2.NR
    Not tested
    Code:
    UPDATE MyTable As MT 
    INNER JOIN 
    (SELECT
        (SELECT COUNT(T1.NR)+1 FROM MyTable As T1 WHERE T1.NR<T2.NR) AS NewNR,
        T2.ID
    FROM MyTable AS T2 
    ORDER BY T2.NR) AS CT
    ON MT.ID=CT.ID 
    SET MT.NR=CT.NewNR
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width