|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Stored Procedure Help
I have two tables that I would like to update with one stored procedure:
Code:
USE GNEITING_HOBS GO CREATE PROCEDURE sp_InsertRooms @HotelID SMALLINT, --RoomTypes @RoomType varchar(15), --RoomTypes @RackRoomRate SMALLMONEY, --RoomTypes --@RoomTypeID int Output --RoomTypes @RoomtypeID smallint, @RoomNumber smallint, @RoomDescription text, @Smoking char, @BedConfiguration char AS INSERT INTO RoomTypes VALUES( @HotelID, --RoomTypes @RoomType, --RoomTypes @RackRoomRate --RoomTypes ) INSERT INTO RoomDetails VALUES( @RoomtypeID, @RoomNumber, @RoomDescription, @Smoking, @BedConfiguration ) The following works, however, I would like to a Primary key from the new value inserted into the Roomtypes table to populate the foreign key in the RoomDetails table. I think I need to use @@IDENTITY some how, but am not sure the syntax? Thanks for any help. |
|
#2
|
|||
|
|||
|
Hi all,
Is someone has answer for this. I have to do the same thing too. Thanks in advance Rainbow11 |
|
#3
|
|||
|
|||
|
Code:
CREATE PROCEDURE sp_InsertRooms @HotelID SMALLINT, --RoomTypes @RoomType varchar(15), --RoomTypes @RackRoomRate SMALLMONEY, --RoomTypes @RoomTypeID int Output, --RoomTypes @RoomNumber smallint, @RoomDescription text, @Smoking char, @BedConfiguration char AS set nocount on INSERT INTO RoomTypes(hotelid,roomtype,rackroomrate) VALUES( @HotelID, --RoomTypes @RoomType, --RoomTypes @RackRoomRate --RoomTypes ) set @RoomTypeID = scope_identity() INSERT INTO RoomDetails VALUES( @RoomtypeID, @RoomNumber, @RoomDescription, @Smoking, @BedConfiguration ) Last edited by swampBoogie : November 6th, 2004 at 01:36 PM. |
|
#4
|
|||
|
|||
|
thanks swampBoogie for answer.
it works for me. thanks again for your time and reply rainbow11 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Stored Procedure Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|