Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to updat a column from start point

how to updat a column from start point

Scheduled Pinned Locked Moved Database
tutorialquestionannouncement
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mhd sbt

    i want to update mycolumn with 10,11,12,..... assume that my table have 100 row then mycolumn with 10,11,...,110 thanks for answer

    T Offline
    T Offline
    thatraja
    wrote on last edited by
    #4

    Still not clear. Update your question with sample data(like BEFORE and AFTER format) with clear explanation. Take your time. before

    A B

    1 1
    2 2

    after

    A B

    2 2
    3 3

    thatraja

    Code converters | Education Needed | Improve EverythingNew

    M 1 Reply Last reply
    0
    • M mhd sbt

      hi to all i want to update a column from start point for example i want to update from 10 .how can i do this columns mycolumn Row1 10 Row2 11 Row3 12 . . . . . .

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #5

      If ye be using SQL Server, then seek thee the ROW_NUMBER function. If not, then at least tell us which database system you are using.

      You'll never get very far if all you do is follow instructions.

      M 1 Reply Last reply
      0
      • T thatraja

        Still not clear. Update your question with sample data(like BEFORE and AFTER format) with clear explanation. Take your time. before

        A B

        1 1
        2 2

        after

        A B

        2 2
        3 3

        thatraja

        Code converters | Education Needed | Improve EverythingNew

        M Offline
        M Offline
        mhd sbt
        wrote on last edited by
        #6

        befor A B ---- 1 NULL 2 NULL 3 NULL 4 NULL after A B ---- 1 10 2 11 3 12 4 13 thanks

        T N 2 Replies Last reply
        0
        • M mhd sbt

          befor A B ---- 1 NULL 2 NULL 3 NULL 4 NULL after A B ---- 1 10 2 11 3 12 4 13 thanks

          T Offline
          T Offline
          thatraja
          wrote on last edited by
          #7

          UPDATE TableName SET ColumnB = ColumnA + 9

          I suggest you to spend more time on SQL basics, it'll save you lot of time.

          thatraja

          Code converters | Education Needed | Improve EverythingNew

          M 1 Reply Last reply
          0
          • T thatraja

            UPDATE TableName SET ColumnB = ColumnA + 9

            I suggest you to spend more time on SQL basics, it'll save you lot of time.

            thatraja

            Code converters | Education Needed | Improve EverythingNew

            M Offline
            M Offline
            mhd sbt
            wrote on last edited by
            #8

            ok but this is just a sample . in column A i have a uniqueidentifier value .how can i write same tsql code that you write? befor A B ---- Guid Null Guid Null . . . . . . after A B ----- Guid 10 Guid 11 , . , . , .

            T 1 Reply Last reply
            0
            • M mhd sbt

              ok but this is just a sample . in column A i have a uniqueidentifier value .how can i write same tsql code that you write? befor A B ---- Guid Null Guid Null . . . . . . after A B ----- Guid 10 Guid 11 , . , . , .

              T Offline
              T Offline
              thatraja
              wrote on last edited by
              #9

              :| This is why should you include all details in your question when you post. You have wasted your time almost 8 hrs. Already @PIEBALDconsult gave you answer[^] by simple guess. Check this thread SQL Update with row_number()[^]

              thatraja

              Code converters | Education Needed | Improve EverythingNew

              1 Reply Last reply
              0
              • P PIEBALDconsult

                If ye be using SQL Server, then seek thee the ROW_NUMBER function. If not, then at least tell us which database system you are using.

                You'll never get very far if all you do is follow instructions.

                M Offline
                M Offline
                mhd sbt
                wrote on last edited by
                #10

                ok thanks for your time. i solved it by code similar this select *,ROW_NUMBER() OVER (ORDER BY [Guid] DESC) + 10 AS RN from tblTest

                M 1 Reply Last reply
                0
                • M mhd sbt

                  ok thanks for your time. i solved it by code similar this select *,ROW_NUMBER() OVER (ORDER BY [Guid] DESC) + 10 AS RN from tblTest

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #11

                  psst see the little arrow that appears next to the post - click that in appreciation of Piebalds help :)

                  Never underestimate the power of human stupidity RAH

                  1 Reply Last reply
                  0
                  • M mhd sbt

                    befor A B ---- 1 NULL 2 NULL 3 NULL 4 NULL after A B ---- 1 10 2 11 3 12 4 13 thanks

                    N Offline
                    N Offline
                    NitinDhapte
                    wrote on last edited by
                    #12

                    Hi, Try this : ColumnA is the primary key of table : tableName

                    UPDATE tableName SET columnB = 9 + t2.RowNum FROM tableName t1 INNER JOIN (
                    SELECT ROW_NUMBER() OVER (ORDER BY columnA) RowNum,columnA FROM tableName) t2 ON t1.columnA = t2.columnA

                    1 Reply Last reply
                    0
                    • M mhd sbt

                      hi to all i want to update a column from start point for example i want to update from 10 .how can i do this columns mycolumn Row1 10 Row2 11 Row3 12 . . . . . .

                      N Offline
                      N Offline
                      NitinDhapte
                      wrote on last edited by
                      #13

                      Hi, Try this : ColumnA is the primary key of table : tableName

                      UPDATE tableName SET columnB = 9 + t2.RowNum FROM tableName t1 INNER JOIN (
                      SELECT ROW_NUMBER() OVER (ORDER BY columnA) RowNum,columnA FROM tableName) t2 ON t1.columnA = t2.columnA

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups