Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query to alter column data

Author  Topic 

techadv
Starting Member

2 Posts

Posted - 2010-03-01 : 23:15:54
hi all,

I was hoping someone can help me out with a query, or at least point me in the right direction.

There is an "item code" column in one of my tables, and I need a query which will add a "zero" into the 3rd position of each code

OLD CODE: 12345
NEW CODE: 120345

Is this possible to do with a query? Thanks in advance.


Cheers ~

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-03-01 : 23:28:54
[code]UPDATE table_name
SET CODE = SUBSTRING(CODE, 1, 2)+ '0' + SUBSTRING(CODE, 3, LEN(CODE))
[/code]



Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-01 : 23:29:38
Try Stuff function:


Select Stuff(12345,3,0,'0')

Regards,
Bohra
Go to Top of Page
   

- Advertisement -