Identity column starting with letters, i.e. wp00001 - wp00008, is it possible?

  • Hello,

    I would like to have an identity colum that increments by a seed of one and starts with two pre-defined letters that never change. Is this possible?

    I have created the identity colum but just need to get the two letters at the start,

    many thanks

  • Do this in the presentational layer of your app.

    SQL Server's build-in IDENTITY property does only work on numeric column with a scale of 0. An alternative would to either use in your queries something like

    SELECT 'XY'+CAST(id_column AS VARCHAR(n))

    or add a computed column to your table. BOL tells you how to do this.

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • A column with the identity property is a surrogate key, and as such should never have any meaning in reality. If you have data that should be labeled as wp00001 (or similar) because it tells something about the data you should not use Identity that way.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply