Domanda

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 !!!

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top