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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Server Calculation Question

Author  Topic 

sandaire
Starting Member

5 Posts

Posted - 2009-01-23 : 04:40:08
Hello:

I am trying to generate a unique consecutive value with SQL Server. My intent is to derive the following:
A00001
A00002
...
A00010
...
A00100
etc...

Is there a way to generate this value in SQL?

Tks,

Johnny

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-23 : 04:44:57
select 'A000' + cast(number as varchar(32)) from master..spt_values where type = 'p'
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-23 : 04:46:04
quote:
Originally posted by bklr

select 'A000' + cast(number as varchar(32)) from master..spt_values where type = 'p'



Bklr but it ends with A0002047 after that it will not generate....
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-01-23 : 04:46:31
You should read this article:

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

- Lumbago
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-23 : 09:26:39
why not use an identity column and then create a computed value based on that?
Go to Top of Page

sandaire
Starting Member

5 Posts

Posted - 2009-01-27 : 10:14:26
The identiy column worked great. I used a combination of the instructinos rom Lumbago and Visakh16 to create the solution. Tks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 12:11:03
welcome
Go to Top of Page
   

- Advertisement -