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. SQL Query for Update Column

SQL Query for Update Column

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadminannouncement
5 Posts 2 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 Offline
    M Offline
    Member 4650287
    wrote on last edited by
    #1

    Hi all, I uploaded some data to SQL Server 2008 from Excel.The table has 4 Fields,After upload the data to Database some of the data in fourth fields are NULL.I need to update the data from first as follows Field1 , Field2 , Field3 , Field4 ABC_XYZ_123 , Office , 432322 , Null XYV_PVC_321 , House , 908000 , 321 MBV_DHC_908 , House , 751232 , 908 MNP_BNM_876 , Office , 125152 , 876 As mentioned above,I need to update first row with 123 which already have in first field. please help me to find to query for solvng above issue. thanks

    B 1 Reply Last reply
    0
    • M Member 4650287

      Hi all, I uploaded some data to SQL Server 2008 from Excel.The table has 4 Fields,After upload the data to Database some of the data in fourth fields are NULL.I need to update the data from first as follows Field1 , Field2 , Field3 , Field4 ABC_XYZ_123 , Office , 432322 , Null XYV_PVC_321 , House , 908000 , 321 MBV_DHC_908 , House , 751232 , 908 MNP_BNM_876 , Office , 125152 , 876 As mentioned above,I need to update first row with 123 which already have in first field. please help me to find to query for solvng above issue. thanks

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      here it is

      UPDATE mytable
      SET field4 =
      (SELECT RIGHT(mt.field1,CHARINDEX('_',mt.field1)-1)
      FROM mytable mt
      WHERE mt.field1 = mytable.field1
      )

      SELECT * FROM mytable


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

      M 1 Reply Last reply
      0
      • B Blue_Boy

        here it is

        UPDATE mytable
        SET field4 =
        (SELECT RIGHT(mt.field1,CHARINDEX('_',mt.field1)-1)
        FROM mytable mt
        WHERE mt.field1 = mytable.field1
        )

        SELECT * FROM mytable


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

        M Offline
        M Offline
        Member 4650287
        wrote on last edited by
        #3

        thanks for you reply.let me try with it

        B 1 Reply Last reply
        0
        • M Member 4650287

          thanks for you reply.let me try with it

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          That should works without problem, I tested it and it worked.


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

          M 1 Reply Last reply
          0
          • B Blue_Boy

            That should works without problem, I tested it and it worked.


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

            M Offline
            M Offline
            Member 4650287
            wrote on last edited by
            #5

            Hello, I tried with above query.But it extracting 10 Digits.I dont know why.I have some datas in Field4 like this "74_125352" actually i need 125352.

            modified on Sunday, May 8, 2011 1:46 AM

            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