Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 generate next number

Author  Topic 

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-11-19 : 15:26:10
How do I generate next avaliable number in my sql statement. Here is my sql

Insert into [Schema].LOOKUP (ID,CODE,DESCRIPTION,LOOKUP_ID_PARENT)
values (:Id, :Code, :Description, :LookupParentId)

where ID is next avaliable number

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-19 : 15:31:31
Use IDENTITY option for the ID column.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-11-19 : 15:36:26
How do you do that?
Go to Top of Page

evilDBA
Posting Yak Master

155 Posts

Posted - 2007-11-19 : 15:38:14
create table LOOKUP (ID int identity, CODE blah blah blah...)
Go to Top of Page

baska123
Yak Posting Veteran

64 Posts

Posted - 2007-11-19 : 15:49:42
I already have a table and I have to work with it. It does not have an identity set up. any other alternatives?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-19 : 15:56:41
Then modify your table so that it does.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -