我试图通过使用单个参数使用SQL query连接两个表。我有两个表student和student job record,我想根据ID将这两个表合并成单个表。
学生档案表。
CREATE TABLE [dbo].[Student_Profile](
[StudentID] [int] IDENTITY(1,1) NOT NULL,
[First_Name] [varchar](50) NULL,
[Last_Name] [varchar](50) NULL,
[Email] [varchar](500) NULL,
[Qualifactions] [varchar](50) NULL,
[Name_Of_Instatutions] [varchar](50) NULL,
[City] [varchar](50) NULL,
[Country] [varchar](50) NULL,
[Contract] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
这是学生工作档案表。
CREATE TABLE [dbo].[Student_Job_Record] (
[Record_ID] [int] IDENTITY(1,1) NOT NULL,
[StudentID] [int] NULL,
[Total_Hours_Work] [varchar](50) NULL,
[Pay_Rate] [varchar](50) NULL,
[Total_Amount_Paid] [varchar](500) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
我正在使用存储过程将数据显示到gridview中。这是存储过程代码。
Create proc [dbo].[spGetStudentsDeatilsByID]
@ID int
as
Begin
SELECT Student_Profile.First_Name, Student_Profile.Last_Name ,Job_Profile.Title,Job_Profile.Location,Job_Profile.Type_Contract,Job_Profile.Salary
FROM Student_Profile ,Job_Profile
WHERE Student_Profile.StudentID =@ID and Job_Profile.StudentID=@ID
End
GO
这是我运行应用程序时的屏幕截图。