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 StudentStatusName
from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Code
left 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.CourseSubjectId
left join FM_StudentContact cc on cc.StudentId=stu.Id
left join FM_SchoolArea scl on scl.Id=stu.SchoolAreaId left join FM_StudentVisitRecord svr on svr.Id=
(select top 1 svr1.Id from FM_Student stu1
join 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.FollowUserID
left join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatus where 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 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)) as ArrearageAmount --欠费金额 from FM_Student stu left join FM_StudentClass sc on stu.Code=sc.Code
left 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.CourseSubjectId
left join FM_StudentContact cc on cc.StudentId=stu.Id
left join FM_SchoolArea scl on scl.Id=stu.SchoolAreaId left join FM_StudentVisitRecord svr on svr.Id=
(select top 1 svr1.Id from FM_Student stu1
join 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.FollowUserID
left join Sys_Dict dict1 on dict1.Type='{1}' and dict1.Code=stu.StudentStatus where 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)
SQL Server case when 日期字符串转换 多表查询 嵌套子查询的更多相关文章
- MS sql server 基础知识回顾(二)-表连接和子查询
		五.表连接 当数据表中存在许多重复的冗余信息时,就要考虑将这些信息建在另一张新表中,在新表中为原表设置好外键,在进行数据查询的时候,就要使用到连接了,表连接就好像两根线,线的两端分别连接两张表的不同字 ... 
- 【网络收集】Sql Server datetime 常用日期格式转换
		) , sfrq, ) 我们经常出于某种目的需要使用各种各样的日期格式,当然我们可以使用字符串操作来构造各种日期格式,但是有现成的函数为什么不用呢? SQL Server中文版的默认的日期字段date ... 
- [SQL SERVER系列]之嵌套子查询和相关子查询
		子查询有两种类型,一种是只返回一个单值的子查询,这时它可以用在一个单值可以使用的地方,这时子查询可以看作是一个拥有返回值的函数:另外一种是返回一列值的子查询,这时子查询可以看作是一个在内存中临时存在的 ... 
- SQL SERVER FOR 多列字符串连接 XML PATH 及 STUFF
		原文:SQL SERVER FOR 多列字符串连接 XML PATH 及 STUFF 本来用 Writer 写一篇关于一列多行合并的博客来的,结果快写完了时候,在一个插入代码时候,崩了,重新打开,居然 ... 
- sql server中的日期详解使用(convert)
		转自:http://blog.csdn.net/hehe520347/article/details/48496853 有个字段值例如2012-07-02 00:00:00.000 转化成 2012- ... 
- SQL Server 2008对日期时间类型的改进
		微软在备受多年的争议后,终于对日期时间数据类型开刀了,在新版的SQL Server 2008中一口气增加了4种新的日期时间数据类型,包括: Date:一个纯的日期数据类型. Time:一个纯的时间数据 ... 
- sql server中的日期函数
		DATEADD 在向指定日期加上一段时间的基础上,返回新的 datetime 值. 语法 DATEADD ( datepart , number, date ) 参数 (1) ... 
- sql server like 在将值转换成数据类型int失败
		select * from table where title like '%'?'%'; 采用? 传参会报错:sql server like 在将值转换成数据类型int失败 select * fro ... 
- SQL Server系统函数:字符串函数
		原文:SQL Server系统函数:字符串函数 1.字符转化为ASCII,把ASCII转化为字符,注意返回的值是十进制数 select ASCII('A'),ASCII('B'),ASCII('a') ... 
随机推荐
- [转载]  Redis
			转载:http://snowolf.iteye.com/blog/1630697 大约一年多前,公司同事开始使用Redis,不清楚是配置,还是版本的问题,当时的Redis经常在使用一段时间后,连接爆满 ... 
- 安装python官方的mysql库“mysql-connector-python”
			$ echo https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz >> ... 
- 【html】button按钮的一些问题
			问题: button 按钮在不设置 type 属性时,在不同的浏览器作用不一样.举个例子: html: <!doctype html> <html lang="en&quo ... 
- ASP.NET MVC 5 局部视图不支持异步问题
			[ChildActionOnly] public async Task<ActionResult> TopLeftFlowPartialView() { var user = Sessio ... 
- 【linux】——FreeBSD 建立 SSH 连接慢的解决方法
			一般在编写 linux 程序的时候,会使用 SecureCRT 或者 xshell 等工具远程登录到 linux 服务器上.最近发现在建立 SSH 连接的时候,非常慢,但是建立连接成功之后可以正常使用 ... 
- [GraphQL] Use GraphQLNonNull for Required Fields
			While certain fields in a GraphQL Schema can be optional, there are some fields or arguments that ar ... 
- Ehcache 使用
			自从Ehcache 到了1.2+的版本,就支持分布式缓存了 Spring + Hibernate的结构 ,ehcache的对这几个框架的支持较好,就采用这个缓存方案 下面是配置文件: <ehca ... 
- JCEF3——谷歌浏览器内核Java版实现(一):使用jawt获取窗体句柄
			前言 最近一段时间研究谷歌浏览器内核.谷歌浏览器内核一直开源,并维护更新,它的开源项目中内核更新速度和Chrome浏览器版本更新进度一样!而且它不同于WebKit(值得一题的是谷歌浏览器已不使用Web ... 
- CentOS 6.5 Python 2.6.6+Flask 用wsgi方式部署在Apache 2.2.15下
			1,安装wsgi Apache模块 easy_install mod_wsgi 2,添加/etc/httpd/conf.d/wsgi.conf LoadModule wsgi_module modul ... 
- [转]使用Cadence ADE + Spectre做Montel Carlo仿真
			1. 工艺模型的选择.以TSMC 180nm工艺为例,1.8V Normal devices 有TT,SS,FF,SF,FS共5种工艺Corner及Montel Carlo(MC)共6种可选用工艺角. ... 
