Home Forums SQL Server 2008 T-SQL (SS2K8) Add Auto Incrementing column to my SELECT statement RE: Add Auto Incrementing column to my SELECT statement

  • my first guess at what you are asking;

    you mentioned hundreds of thousands, but your pattern only allows 99999 values.

    note i'm still using an identity and a default value in order to generate the code example you asked for...not using it replace them.

    /*

    --Results

    IDSomeDataCreatedateCalculatedDescriptor

    1first2013-04-0120130401GP00001

    2second2013-04-0120130401GP00002

    */

    CREATE TABLE Example(

    ID int identity(1,1) not null primary key,

    SomeData varchar(30),

    Createdate date default getdate(),

    CalculatedDescriptor AS CONVERT(varchar,Createdate,112) + 'GP' + RIGHT('00000' + convert(varchar,ID),5) )

    insert into Example(SomeData) values('first'),('second')

    select * from Example

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!