Connecting Tech Pros Worldwide Forums | Help | Site Map

how to update set some added string

Member
 
Join Date: Sep 2006
Posts: 73
#1: Nov 11 '08
i have tblPeribadi as table of database
i want to add some string to each row for column kod_pusat_kos
maybe like this..
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblPeribadi SET Kod_Pusat_Kos='00'+Kod_Pusat_Kos WHERE Kod_Pusat_Kos>10000001



ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Nov 11 '08

re: how to update set some added string


what's the data type of kod_pusat_kos ?


-- CK
Member
 
Join Date: Sep 2006
Posts: 73
#3: Nov 11 '08

re: how to update set some added string


kod_pusat_kos char(10)
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#4: Nov 11 '08

re: how to update set some added string


Yes you can concatenate the data to the existing value of the column but that should not exceed 10 Characters
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#5: Nov 11 '08

re: how to update set some added string


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


Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE tblPeribadi 
  3. SET Kod_Pusat_Kos=right('0000000000'+Kod_Pusat_Kos,10)
  4. WHERE cast(Kod_Pusat_Kos as int) >10000001
  5.  
  6.  
Happy coding!

-- CK
Member
 
Join Date: Sep 2006
Posts: 73
#6: Nov 17 '08

re: how to update set some added string


Quote:

Originally Posted by ck9663

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


Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE tblPeribadi 
  3. SET Kod_Pusat_Kos=right('0000000000'+Kod_Pusat_Kos,10)
  4. WHERE cast(Kod_Pusat_Kos as int) >10000001
  5.  
  6.  
Happy coding!

-- CK

Thanks CK and i did it with LEFT
Reply