且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server 2008 R2的数据库错误

更新时间:2023-02-03 10:09:36

您忘了在查询中添加表学生。 br />
  SELECT  EquipmentName,EquipmentModel,Description,[Equipment  Type  Id],DateInRoom,TimeInRoom 
FROM 设备, 学生 WHERE Equipment.StudentNumber = Student.StudentNumber AND Equipment.StudentNumber=@studentNumber


  CREATE   PROCEDURE  [dbo]。[uspStudentEquipment ] 
@ studentNumber nvarchar 50
AS
BEGIN
SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
FROM 设备
WHERE Equipment.StudentNumber=@studentNumber
END
GO





试试这个






你可以这样做,它会解决你的要求



  CREATE  程序 [dbo]。[uspStudentEquipment] 
@ studentNumber nvarchar 50
AS
BEGIN
选择 * SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
FROM 设备,学生
WHERE Equipment.StudentNumber = Student.StudentNumber
as x 其中​​ x.StudentNumber=@studentNumber
END
GO



问候

Mubin


Hi all

Here's my stored procedure for a select statement

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

You forgot to add the table Student in your query.
SELECT EquipmentName,EquipmentModel,Description,[Equipment Type Id],DateInRoom,TimeInRoom
    FROM Equipment, Student    WHERE Equipment.StudentNumber = Student.StudentNumber AND Equipment.StudentNumber=@studentNumber


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


Hi,

You can go for this, it will solve your requirement

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