MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2004, 03:01 AM
travis801 travis801 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 6 travis801 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old November 6th, 2004, 12:07 PM
rainbow11 rainbow11 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 86 rainbow11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 22 sec
Reputation Power: 5
Hi all,
Is someone has answer for this.
I have to do the same thing too.
Thanks in advance
Rainbow11

Reply With Quote
  #3  
Old November 6th, 2004, 01:33 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
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.

Reply With Quote
  #4  
Old November 6th, 2004, 10:42 PM
rainbow11 rainbow11 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 86 rainbow11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 15 m 22 sec
Reputation Power: 5
thanks swampBoogie for answer.
it works for me.
thanks again for your time and reply

rainbow11

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Stored Procedure Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT