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)
 Stored Proc Adding Record and Retreiving new ID

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-02-25 : 10:58:24
Dawie writes "



The tabel Reservations
ReservationKey PK,
GuestKey FK.


/*
create procedure spInsert_Reservation
(@intNewReservationKey int output
,@intGuestKey int)
as
insert into Reservations
(GuestKey)
Values
(@intGuestKey)
Set @intNewReservationKey = (select max(reservationkey) from reservations)
*/

/*
declare @MyNewReservationKey int
execute spInsert_Reservation @MyNewReservationKey output, 2
select 'New Key: ' , @myNewReservationKey
*/


I dont like using SELECT MAX(RESERVATIONKEY)
What if another user created a record a second after me??"
   

- Advertisement -