Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Here's my stored procedure for a select statement
SQL
CREATE PROCEDURE [dbo].[uspStudentEquipment]
@studentNumber nvarchar (50)
AS
BEGIN
	SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
	FROM Equipment 
	WHERE Equipment.StudentNumber = Student.StudentNumber AND Equipment.StudentNumber=@studentNumber
END
GO

-When I execute this stored procedure i get this error message:

Msg 4104, Level 16, State 1, Procedure uspStudentEquipment, Line 12
The multi-part identifier "Student.StudentNumber" could not be bound.

I am not too sure what this error means. Could anyone please help?
Thanks
Posted
Updated 6-Sep-13 4:27am
v3
Comments
TryAndSucceed 6-Sep-13 10:33am    
I think you need to add Student table beside your equipment table i.e.
From Equipement, Student

You forgot to add the table Student in your query.
SQL
SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
    FROM Equipment, Student    WHERE Equipment.StudentNumber = Student.StudentNumber AND Equipment.StudentNumber=@studentNumber
 
Share this answer
 
v2
Comments
phil.o 6-Sep-13 12:32pm    
See my comment to solution 2 :)
SQL
CREATE PROCEDURE [dbo].[uspStudentEquipment]
@studentNumber nvarchar (50)
AS
BEGIN
    SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
    FROM Equipment
    WHERE Equipment.StudentNumber=@studentNumber
END
GO


try this
 
Share this answer
 
Comments
thatraja 6-Sep-13 10:33am    
why(did you remove that criteria)? He needs the join to fetch matching records.
Gitanjali Singh 6-Sep-13 10:36am    
that is not join.
thatraja 6-Sep-13 10:40am    
then what?
phil.o 6-Sep-13 12:27pm    
He's right, that is no join.
No column of Student table is included in SELECT clause ; so there is no point to join both tables. The condition is here managed with the variable @studentNumber.
I upvoted the solution, because we cannot say this procedure is incorrect with what the OP has given to us.
Hi,

You can go for this, it will solve your requirement

SQL
CREATE PROCEDURE [dbo].[uspStudentEquipment]
@studentNumber nvarchar (50)
AS
BEGIN
	select * from (SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
	FROM Equipment,student
	WHERE Equipment.StudentNumber = Student.StudentNumber 
	)as x where  x.StudentNumber=@studentNumber
END
GO

Regards
Mubin
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900