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

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-01-13 : 14:47:07
[code]
I need a query to autoincrement the value with number.

Ex:

Table1:

Value varchar(10)

value
-----
KOO0
QOO0
TOO0


Expected output:

value
-----
KOO01
QOO02
TOO03

[/code]

Thanks for your help in advance..

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-13 : 15:04:14
What's the increment ordered by? The value? Does it ever reset?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-01-13 : 15:13:35
Thanks GilaMonster..
Increment order is by values and it does not reset..
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-13 : 15:27:48
SELECT [value] + CAST(Row_Number() OVER (order by [value]) AS Varchar(4)) FROM ....

Not tested since you didn't provide table definitions, but should give the general idea.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-01-13 : 15:36:31
Thanks it works..
Go to Top of Page
   

- Advertisement -