Monday, March 19, 2012

identity seed

Hello,
How can i set a identity column to start with 01 instead of 1?
ThnxIdentity values are integers, and the value of 01 an 1 are identical. So
there is no difference...
Is there something more in your question?
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Samuel" <samuel@.hotrmail.com> wrote in message
news:%23E7VLd5rEHA.192@.tk2msftngp13.phx.gbl...
> Hello,
> How can i set a identity column to start with 01 instead of 1?
> Thnx
>|||Hi Wayne,
I just wanted to start from 01.
How about related tables where i want the identity must start with 001 if
the main table starts with 1. For each new record in the main table, the
related table must rebuild the identiy to begin with 001.
"Wayne Snyder" <wayne.nospam.snyder@.mariner-usa.com> wrote in message
news:eNGWeh5rEHA.4032@.TK2MSFTNGP12.phx.gbl...
> Identity values are integers, and the value of 01 an 1 are identical. So
> there is no difference...
> Is there something more in your question?
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Samuel" <samuel@.hotrmail.com> wrote in message
> news:%23E7VLd5rEHA.192@.tk2msftngp13.phx.gbl...
>|||"Samuel" <samuel@.hotrmail.com> wrote in message
news:eFqh675rEHA.2732@.TK2MSFTNGP09.phx.gbl...
> I just wanted to start from 01.
> How about related tables where i want the identity must start with 001 if
> the main table starts with 1. For each new record in the main table, the
> related table must rebuild the identiy to begin with 001.
Samuel,
'001' is a formatted string version of the number 1. Identity values
are numeric and have no format. If you need to left-pad for display
purposes, you can use the following pattern:
SELECT RIGHT(REPLICATE('0', <n> ) + YourCol, <n> ) AS FormattedYourCol
FROM YourTable
Replace the <n>s in the above with the maximum length of the formatted
output string you'd like.

No comments:

Post a Comment