Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

i have thousand of records to update.my question is like this in my table this is the Reg_no(primary key)

REG_NO
Ex VT/abc/2015/001
VT/abc/2015/002
VT/abc/2015/003
VT/abc/2015/004
VT/abc/2015/005
.
.
more

but i want to change this 3 token 2015 into 2014
ex :
REG_NO
VT/abc/2014/001
VT/abc/2014/002
VT/abc/2014/003
VT/abc/2014/004
.
.
more


please help me
Posted

1 solution

Try something like this:

SQL
UPDATE table1
SET field1 = REPLACE(field1, '2014', '2015')


However, if these are really primary keys and may be pointing to other tables then you may have a big problem. I would suggest you don't do primary keys like this but use a guid or identity field instead.
 
Share this answer
 
Comments
nuke_infer 24-Mar-15 11:30am    
you mean UPDATE table1 SET reg_no = (reg_no,'2014',2015); ?
ZurdoDev 24-Mar-15 11:30am    
UPDATE table1 SET reg_no = REPLACE(reg_no,'2014',2015)

This will replace the string 2014 in reg_no to 2015.
nuke_infer 24-Mar-15 11:33am    
but friend there is mixing with 2014 and 2015 in that key. therefor i want to check these record id if it is 2015 then change as a 2014 if not its ok like wise.how can i do it? please help me i confused about this
ZurdoDev 24-Mar-15 11:33am    
I don't understand.
nuke_infer 24-Mar-15 11:36am    
ex : VT/abc/2014/001
VT/abc/2014/002
VT/abc/2014/003
VT/abc/2015/004
VT/abc/2015/005

now it has a 2014 and 2015 both.but i want to change this 2015 into 2014 ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900