Question

I have created two tables as shown in the diagram

enter image description here

I want to retrieve Name Address and SubjectName in a single stored procedure

I have written stored procedure as

ALTER proc [dbo].[prStudentFetchALL]
as
Select StudentId, Name, Address, SubjectId from [tbStudent] 

I want to retrieve SubjectName instead of SubjectId

Please help me !!!

Was it helpful?

Solution

You need to JOIN those tables:

ALTER proc [dbo].[prStudentFetchALL]
as
Select S.StudentId, S.Name, S.Address, Sub.SubjectName 
from tbStudent S JOIN
     tbSubject Sub ON S.SubjectId =Sub.SubjectId 

Learn more about JOIN at w3schools or blog.sqlauthority.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top