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
 General SQL Server Forums
 Database Design and Application Architecture
 Help needed with insert stored procedure

Author  Topic 

sm2010
Starting Member

2 Posts

Posted - 2010-04-01 : 21:19:38
Hi All,

i am having problems trying to run an stored procedure. i have two tables, and the one contains the foreign key of the other and i created an insert statement to inser the data in both tables. Can anyone please help me in solving this problem.

Any help much appreciated. Thanks.

here is the stored procedure code:
ALTER PROCEDURE [dbo].[contractRoomDetails]


@Duration varchar(10),
@NoOfHours int,
@RoomNo nchar(6),
@Classroom varchar(3),
@Hall varchar(3),
@Date varchar(50),
@StartTime varchar(50),
@FinishTime varchar(50)

AS
BEGIN
Set NoCount on
DECLARE @ContractID varchar(6)

INSERT INTO Contract (Duration, NoOfHours) VALUES (@Duration, @NoOfHours)

Select @ContractID=@@Identity

INSERT INTO RoomBooking (RoomNo, Classroom, Hall, Date, StartTime, FinishTime, ContractID) VALUES (@RoomNo, @Classroom, @Hall, @Date, @StartTime, @FinishTime, @ContractID)
END


and to test it i tried to put in these values:
exec contractRoomDetails 'cn14', '4months', '13', 'rm3', 'yes', 'no', '13/09/09', '2pm', '3pm'

BUT the error message i keep getting is :

Msg 8144, Level 16, State 2, Procedure contractRoomDetails, Line 0
Procedure or function contractRoomDetails has too many arguments specified


S.M

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-01 : 21:43:47
You are passing 9 values to your stored procedure, yet it only accepts 8 parameters.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sm2010
Starting Member

2 Posts

Posted - 2010-04-02 : 17:43:35
hi,
The 9th value is the customerID, wen i try and put it in the list under ALTER PROCEDURE, it says that it is already declared. the customerID is the PK in the contract table and a FK in the volunteer table. how do i declare these?

Many Thanks

S.M
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-02 : 17:57:54
I'm very confused now.

It appears the parameter for 'cn14' isn't an input parameter.

You're @ContractID is incorrect also. You've declared it as varchar(6), yet you are trying to capture an integer value in it with @@IDENTITY. The identity should be int (or some other integer data type, not varchar).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -