国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SQL Server case when 日期字符串轉換 多表查詢 嵌套子查詢

2024-08-31 00:55:41
字體:
來源:轉載
供稿:網友
SQL Server case when 日期字符串轉換 多表查詢 嵌套子查詢
select distinct stu.*,dbo.GetClassNameByStudentCode(stu.Code) as ClassName,dbo.GetCourseNameByStudentCode(stu.Code) as CourseName,dbo.GetLinkmanByStudentId(stu.Id) as Linkman,dbo.GetContactByStudentId(stu.Id) as Contact,case when svr.Linkman is not NULL then svr.Linkman else dbo.GetLinkmanByStudentId(stu.Id) end as VisitLinkman,case when svr.Contact is not NULL then svr.Contact else dbo.GetContactByStudentId(stu.Id) end as VisitContact,case when u1.Sname is not NULL and u1.Sname<>'' then u1.Sname else u1.Username end as VisitFollowUserName,CONVERT(CHAR(10), svr.FollowTime, 23) as VisitLastFollowTime,scl.Name as SchoolAreaName,svr.ContentMemo as VisitContentMemo,dict1.Name as StudentStatusNamefrom FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Codeleft join FM_Class cls on cls.ClassCode=sc.ClassCode left join FM_Course cou on cou.Id=cls.CourseId left join FM_CourseSubject cs on cs.Id=cou.CourseSubjectIdleft join FM_StudentContact cc on cc.StudentId=stu.Idleft join FM_SchoolArea scl on scl.Id=stu.SchoolAreaIdleft join FM_StudentVisitRecord svr on svr.Id=(select top 1 svr1.Id from FM_Student stu1join FM_StudentVisitRecord svr1 on stu1.Code=svr1.Code and stu1.Id=stu.Id order by svr1.Id desc)left join Sys_User u1 on u1.Id=svr.FollowUserIDleft join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatuswhere stu.DelFlg<>{0}

select distinct stu.*,scl.Name as SchoolAreaName,dbo.GetClassNameByStudentCode(stu.Code) as ClassName,dbo.GetCourseNameByStudentCode(stu.Code) as CourseName,dbo.GetLinkmanByStudentId(stu.Id) as Linkman,dbo.GetContactByStudentId(stu.Id) as Contact,case when svr.Linkman is not NULL then svr.Linkman else dbo.GetLinkmanByStudentId(stu.Id) end as VisitLinkman,case when svr.Contact is not NULL then svr.Contact else dbo.GetContactByStudentId(stu.Id) end as VisitContact,svr.ContentMemo as VisitContentMemo,case when u1.Sname is not NULL and u1.Sname<>'' then u1.Sname else u1.Username end as VisitFollowUserName,CONVERT(CHAR(10), svr.FollowTime, 23) as VisitLastFollowTime,dict1.Name as StudentStatusName,((select sum(pf.PayAmount) from FM_PayFlow pfjoin FM_Student stu1 on pf.CustomerCode=stu1.Code and stu1.Code=stu.Code) -(select sum(psf.PayAmount) from FM_PayStepFlow psf join FM_PayFlow pf1 on psf.PayFlowId=pf1.Idjoin FM_Student stu1 on pf1.CustomerCode=stu1.Code and stu1.Code=stu.Code))  as ArrearageAmount --欠費金額from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Codeleft join FM_Class cls on cls.ClassCode=sc.ClassCode left join FM_Course cou on cou.Id=cls.CourseId left join FM_CourseSubject cs on cs.Id=cou.CourseSubjectIdleft join FM_StudentContact cc on cc.StudentId=stu.Idleft join FM_SchoolArea scl on scl.Id=stu.SchoolAreaIdleft join FM_StudentVisitRecord svr on svr.Id=(select top 1 svr1.Id from FM_Student stu1join FM_StudentVisitRecord svr1 on stu1.Code=svr1.Code and stu1.Id=stu.Id order by svr1.Id desc)left join Sys_User u1 on u1.Id=svr.FollowUserIDleft join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatuswhere stu.DelFlg<>{0} and (sc.Status='{2}' or sc.Status is NULL         and            (select sum(pf.PayAmount)         from FM_PayFlow pf        join FM_Student stu1 on pf.CustomerCode=stu1.Code and stu1.Code=stu.Code) >        (select sum(psf.PayAmount)         from FM_PayStepFlow psf         join FM_PayFlow pf1 on psf.PayFlowId=pf1.Id        join FM_Student stu1 on pf1.CustomerCode=stu1.Code and stu1.Code=stu.Code)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀化市| 宿松县| 巴青县| 凤山市| 宿州市| 栾城县| 兰州市| 新民市| 曲靖市| 吴桥县| 香格里拉县| 五大连池市| 海林市| 荆州市| 博爱县| 库伦旗| 岗巴县| 浙江省| 米林县| 木里| 五华县| 安岳县| 股票| 青浦区| 翼城县| 兴化市| 开鲁县| 台北县| 麦盖提县| 微博| 郴州市| 南召县| 舞钢市| 屏山县| 峨眉山市| 郎溪县| 营山县| 岳池县| 连平县| 巨野县| 永定县|