需要将 3 个表中的值插入另一个名为myTable
. myTable 中的必填字段为:
[Id_student] int,
[id_subjects] int
[degrees] float
[st_Name] nvarchar(30)
[Id_Class] int
[Id_Group] int
[Class] nvarchar(15)
[group] nvarchar(15))` ..
我在下面创建了存储过程。但是查看表格后发现只保存了传递的参数!即@Id_student , @id_subjects , @degrees
。谁能解释这段代码有什么问题?
CREATE storedprocedure mySp_myTable_insert
@Id_student int,
@id_subjects int,
@degrees int
as
DECLARE @st_Name nvarchar(30)
SELECT @st_Name = pst.st_Name FROM dbo.sudents AS pst where pst.id_student=@id_student ;
INSERT [myTable]
(
[Id_student],
[id_subjects],
[degrees],
[st_Name],
[Id_Class],
[Id_Group],
[Class],
[group]
)
(select
@Id_student,
@id_subjects,
@degrees,
@st_Name
,tc.Id_Class
,tg.Id_Group
,tc.Class
,tg.group
from dbo.subjects sbj
inner join tGroup tg
inner join tClass tc
on tc.Id_Class=tg.Id_Class
on sbj.Id_Group =tg.Id_Group
where sbj.id_subjects=@id_subjects)