Friday, March 9, 2012

Identity Function

Hi,
I need to use the identity function as below except SQL server doesn't
appear to like it unless I specify the seed as a literal.
select identity(int, @.seed, 1)
into ...
Is there a possible work around?
Thanks,
BryanBB wrote:
> Hi,
> I need to use the identity function as below except SQL server doesn't
> appear to like it unless I specify the seed as a literal.
> select identity(int, @.seed, 1)
> into ...
> Is there a possible work around?
> Thanks,
> Bryan
You'll have to resort to dynamic SQL if you need a data-drive seed
value.
David Gugick
Imceda Software
www.imceda.com|||>> I need to use the identity function <<
Amazing, but I have been writing SQL for about two decades and I have
never had to use the identity function. Instead of telling how you
have decided to kludge the problem, could you tell us what that problem
is first? Please post DDL, so that people do not have to guess what
the keys, constraints, Declarative Referential Integrity, datatypes,
etc. in your schema are. Sample data is also a good idea, along with
clear specifications.|||As David suggested, you could use dynamic SQl, but to make it a bit easier,
You could just do the Select Into using Seed = 1, then run the following to
reset the seed t othe dynamic value you want...
Declare @.Seed TinyInt Set @.Seed = 1
Declare @.Sql VarChar(50)
Set @.Sql = 'Dbcc CheckIdent(NewTable, ReSeed, ' + Str(@.Seed,3) +')'
Exec (@.Sql)
"David Gugick" wrote:

> BB wrote:
> You'll have to resort to dynamic SQL if you need a data-drive seed
> value.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>|||Thanks to everyone that responded.
"BB" <reply@.to.group.com> wrote in message
news:OUUcsJ7OFHA.4000@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I need to use the identity function as below except SQL server doesn't
> appear to like it unless I specify the seed as a literal.
> select identity(int, @.seed, 1)
> into ...
> Is there a possible work around?
> Thanks,
> Bryan
>

No comments:

Post a Comment