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 2000 Forums
 SQL Server Development (2000)
 Basic Question

Author  Topic 

label
Posting Yak Master

197 Posts

Posted - 2003-04-28 : 12:27:23
What's the best way to get an Indentity/Unique ID from a record after adding it?

For instance My stored proc is this:

_____________________________________________

CREATE PROCEDURE dbo.ap_add_download_page

@username varchar(50),
@page_name varchar(50),
@page_desc varchar(200),
@pageid int output

AS

begin

set nocount on

insert into download_pages (page_name, page_description, created_by, created_on)
select @page_name, @page_desc, (select userid from users where email=@username), getdate()

End
GO
____________________________________________


So what's the line I need to add to populate the @Pageid output parameter?

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-04-28 : 12:30:30
SELECT @pageid = @@IDENTITY

Also have a look at SCOPE_IDENTITY and IDENT_CURRENT.

Tara
Go to Top of Page

label
Posting Yak Master

197 Posts

Posted - 2003-04-28 : 13:56:27
quote:

SELECT @pageid = @@IDENTITY

Also have a look at SCOPE_IDENTITY and IDENT_CURRENT.

Tara



Thanks. I'll do that.

Go to Top of Page
   

- Advertisement -