Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

increment string column by 1

Status
Not open for further replies.

happyIndian100

Programmer
Jul 20, 2003
66
US
I have a Table Product with the following data:

ID productCode Productname
------------------------------
1 sdk/mini/011 AAAA
2 ngs/kitt/2134 BBB
3 smd/ti/022 CCC

now i need to increment all the ProductCodes by one.
the result should be

ID ProductCode ProductName
------------------------------
1 sdk/mini/012 AAAA
2 ngs/kitt/2135 BBB
3 smd/ti/023 CCC

Please help me to write this query..

thx in advance


 
You should hold the product code as separate fields.

update tbl
set productCode = left(productCode,len(productCode)-charindex('/',reverse(productCode))+1) + right(replicate('0',100) + convert(varchar(10),convert(int,right(productCode,charindex('/',reverse(productCode))-1))+1),charindex('/',reverse(productCode))-1)


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top