how to update set some added string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MATTXtwo
    New Member
    • Sep 2006
    • 83

    how to update set some added string

    i have tblPeribadi as table of database
    i want to add some string to each row for column kod_pusat_kos
    maybe like this..
    Code:
    UPDATE tblPeribadi SET Kod_Pusat_Kos='00'+Kod_Pusat_Kos WHERE Kod_Pusat_Kos>10000001
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    what's the data type of kod_pusat_kos ?


    -- CK

    Comment

    • MATTXtwo
      New Member
      • Sep 2006
      • 83

      #3
      kod_pusat_kos char(10)

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Yes you can concatenate the data to the existing value of the column but that should not exceed 10 Characters

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          If you're considering of left-padding your column with zeros, consider this:


          Code:
          UPDATE tblPeribadi 
          SET Kod_Pusat_Kos=right('0000000000'+Kod_Pusat_Kos,10)
          WHERE cast(Kod_Pusat_Kos as int) >10000001
          Happy coding!

          -- CK

          Comment

          • MATTXtwo
            New Member
            • Sep 2006
            • 83

            #6
            Originally posted by ck9663
            If you're considering of left-padding your column with zeros, consider this:


            Code:
            UPDATE tblPeribadi 
            SET Kod_Pusat_Kos=right('0000000000'+Kod_Pusat_Kos,10)
            WHERE cast(Kod_Pusat_Kos as int) >10000001
            Happy coding!

            -- CK
            Thanks CK and i did it with LEFT

            Comment

            Working...