国产探花免费观看_亚洲丰满少妇自慰呻吟_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)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴业县| 清水河县| 米泉市| 和平区| 广元市| 福州市| 文登市| 喀喇沁旗| 翁源县| 曲沃县| 马关县| 海安县| 安阳市| 永川市| 吐鲁番市| 万全县| 太仆寺旗| 德州市| 肥东县| 芜湖市| 西昌市| 德安县| 奉新县| 泽州县| 金川县| 若尔盖县| 竹北市| 肥东县| 嘉兴市| 玉林市| 延庆县| 仪陇县| 米脂县| 千阳县| 八宿县| 兴国县| 九寨沟县| 津南区| 拜城县| 潼关县| 太原市|