Вопрос

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