我通过以下查询创建了视图,但是从该视图中选择数据时,它为同一个学生生成多行我的意思是它必须根据[studentsledger]表生成数据,而不是来自currentacademicinformation表,因为如果1个学生已经通过了1个班级目前,如果他正在阅读2级课程,那么它会产生2行不应该是因为学生已经存储了学生付账单的表格?
CREATE VIEW [dbo].[StudentLedgerView]
AS
SELECT
dbo.StudentsLedger.StudentLedgerId,
dbo.StudentsLedger.FiscalYearId,
dbo.FiscalYears.FiscalYearName,
dbo.StudentsLedger.AcademicSessionId,
dbo.AcademicSessions.Name,
dbo.StudentsLedger.StudentId,
dbo.StudentPersonalInformations.CodeNumber,
dbo.StudentPersonalInformations.FirstName + ' ' + dbo.StudentPersonalInformations.MiddleName + ' ' + dbo.StudentPersonalInformations.LastName AS StudentName,
dbo.StudentsLedger.SystemEntryDate, dbo.StudentsLedger.DateAD,
dbo.StudentsLedger.DateBS, dbo.StudentsLedger.ReceiptNumber,
dbo.StudentsLedger.ReceiptGeneratedBy,
dbo.UserDetails.Name AS ReceiptPreparedBy,
dbo.StudentsLedger.ReceivedAmount, dbo.StudentsLedger.ReturnAmount,
dbo.StudentsLedger.TotalAmount,
dbo.StudentsLedger.TotalDiscount, dbo.StudentsLedger.TotalFine,
dbo.StudentsLedger.TotalAdjustedFine,
dbo.StudentsLedger.IsCancelled,
dbo.StudentsLedgerDetails.StudentLedgerDetailId,
dbo.StudentsLedgerDetails.FeeSetupId,
dbo.StudentsLedgerDetails.Particulars,
dbo.StudentsLedgerDetails.Amount,
dbo.StudentsLedgerDetails.TaxAmount,
dbo.StudentsLedgerDetails.AdjustedAmount,
dbo.StudentsLedgerDetails.MonthName, dbo.LevelsName.LevelName,
dbo.Classes.ClassName,
dbo.Faculties.FacultyName, dbo.Programs.ProgramFullName,
dbo.CurrentAcademicInformations.Section,
dbo.CurrentAcademicInformations.RollNumber,
dbo.CurrentAcademicInformations.LevelNameId,
dbo.CurrentAcademicInformations.ProgramId,
dbo.CurrentAcademicInformations.YearSem,
dbo.CurrentAcademicInformations.ClassId,
dbo.CurrentAcademicInformations.FacultyId
FROM
dbo.StudentsLedger
INNER JOIN
dbo.AcademicSessions ON dbo.StudentsLedger.AcademicSessionId = dbo.AcademicSessions.AcademicSessionId
LEFT JOIN
dbo.FiscalYears ON dbo.StudentsLedger.FiscalYearId = dbo.FiscalYears.FiscalYearId
LEFT JOIN
dbo.StudentsLedgerDetails ON dbo.StudentsLedger.StudentLedgerId = dbo.StudentsLedgerDetails.StudentLedgerId
LEFT JOIN
dbo.StudentPersonalInformations ON dbo.StudentsLedger.StudentId = dbo.StudentPersonalInformations.StudentPersonalInformationId
LEFT JOIN
dbo.UsersInfo ON dbo.StudentsLedger.ReceiptGeneratedBy = dbo.UsersInfo.UserId
LEFT OUTER JOIN
dbo.UserDetails ON dbo.UsersInfo.UserId = dbo.UserDetails.UserId
LEFT JOIN
dbo.CurrentAcademicInformations ON dbo.StudentPersonalInformations.StudentPersonalInformationId = dbo.CurrentAcademicInformations.StudentId
LEFT OUTER JOIN
dbo.LevelsName ON dbo.CurrentAcademicInformations.LevelNameId = dbo.LevelsName.LevelNameId
LEFT OUTER JOIN
dbo.Classes ON dbo.CurrentAcademicInformations.ClassId = dbo.Classes.ClassId
LEFT OUTER JOIN
dbo.Faculties ON dbo.CurrentAcademicInformations.FacultyId = dbo.Faculties.FacultyId
LEFT OUTER JOIN
dbo.Programs ON dbo.CurrentAcademicInformations.ProgramId = dbo.Programs.ProgramId AND dbo.Faculties.FacultyId = dbo.Programs.FacultyId
GO