微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQL Server case when 日期字符串转换 多表查询 嵌套子查询

select distinct stu.*,
dbo.GetClassNameByStudentCode(stu.Code) as ClassName,dbo.GetCourseNameByStudentCode(stu.Code) CourseName,dbo.GetLinkmanByStudentId(stu.Id) Linkman,dbo.GetContactByStudentId(stu.Id) Contact,
case when svr.Linkman is not NULL then svr.Linkman else dbo.GetLinkmanByStudentId(stu.Id) end VisitLinkman,when svr.Contact then svr.Contact else dbo.GetContactByStudentId(stu.Id) VisitContact,1)">when u1.Sname NULL and u1.Sname<>'' then u1.Sname else u1.Username VisitFollowUserName,1)">CONVERT(CHAR(10),svr.FollowTime,23) VisitLastFollowTime,
scl.Name as SchoolAreaName,
svr.ContentMemo as VisitContentMemo,
dict1.Name as StudentStatusName
from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Code join FM_Class cls on cls.ClassCodesc.ClassCode join FM_Course cou on cou.Idcls.CourseId join FM_CourseSubject cs on cs.Idcou.CourseSubjectId join FM_StudentContact cc on cc.StudentIdstu.Id join FM_SchoolArea scl on scl.Idstu.SchoolAreaId join FM_StudentVisitRecord svr on svr.Id (top 1 svr1.Id FM_Student stu1 join FM_StudentVisitRecord svr1 on stu1.Code=svr1.Code and stu1.Id=stu.Id order by svr1.Id desc) join Sys_User u1 on u1.Idsvr.FollowUserID join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Codestu.StudentStatus where stu.DelFlg<>{0}

 

*,scl.Name  SchoolAreaName,dbo.GetClassNameByStudentCode(stu.Code)  VisitContentMemo,dict1.Name  StudentStatusName,((select sum(pf.PayAmount) 
 FM_PayFlow pf
join FM_Student stu1 on pf.CustomerCode=stu1.Code and stu1.Code=stu.Code) -

((psf.PayAmount) 
 FM_PayStepFlow psf 
join FM_PayFlow pf1 on psf.PayFlowIdpf1.Id
on pf1.CustomerCode=stu.Code))  as ArrearageAmount --欠费金额

0} and (sc.Status{2}or sc.Status is NULL 
        and    
        ((pf.PayAmount) 
         FM_PayFlow pf
        >

        ((psf.PayAmount) 
         FM_PayStepFlow psf 
        pf1.Id
        =stu.Code)

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐