Pou Thapioume D
Pou Thapioume D

Reputation: 3

SQL Server copy a column to a new one but with different string pattern

I have a column in a table (profiles) called profile_p with 2399 records with the following string pattern

profile_p + 10 digit unique ID      (ex: profile_p1234567890) 

Now what I want to do is:
create another new column inside this table and copy all these records BUT with the following string pattern

profile_p_th + 10 digit unique ID     (ex: profile_p_th1234567890)

The id stays same what I want to change is profile_p to profile_p_th

Upvotes: 0

Views: 44

Answers (1)

apartridge
apartridge

Reputation: 1820

This should work for you.

UPDATE profiles SET newcolumn=REPLACE(profile_p, 'profile_p', 'profile_p_th')

But why don't you just store the numerical string without this constant prefix?

Upvotes: 1

Related Questions