문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top