Solved

Tempdb IDENTITY as Variable

Posted on 2004-09-15
5
184 Views
Last Modified: 2006-11-17
--Why does this not work?

declare @myNumber integer

set @myNumber = 501

DROP TABLE  [#myTEMP]

CREATE TABLE [#myTEMP]
      (
      [myFIELD] [int] IDENTITY( @myNumber,  1) NOT NULL
      )
0
Comment
Question by:SurferJoe
5 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 75 total points
ID: 12070413
The CREATE TABLE doesn't allow for a variable, however you can CREATE with value 1 then immediately RESEED to something else :

declare @myNumber integer

set @myNumber = 501

DROP TABLE  [#myTEMP]

CREATE TABLE [#myTEMP]
     (
     [myFIELD] [int] IDENTITY( 1,  1) NOT NULL
     )

DBCC CHECKIDENT ('#myTEMP', RESEED, @MyNumber)
0
 
LVL 42

Assisted Solution

by:EugeneZ
EugeneZ earned 75 total points
ID: 12070765
or  you can try global temp table (or regular table):

declare @myNumber integer
declare @str nvarchar(1000)
set @myNumber = 501

DROP TABLE  ##myTEMP

set @str ='CREATE TABLE ##myTEMP
     (
     [myFIELD] [int] IDENTITY(' + cast(@myNumber as varchar(10)) + ',  1) NOT NULL
     )'
--print @str
exec(@str)

select * from ##myTEMP
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now