干货

CREATE TABLE #benefit_code21 (id INT,
number nvarchar(MAX),
pname nvarchar(255),
collegeID INT,
applicationdate datetime,
authorizedate datetime,
lawState int,
lawTime datetime,
country nvarchar(255),
category nvarchar(255),
mainCategoryNumber nvarchar(255),
allCategoryNumber nvarchar(255),
typess int,
levelss int,
Introduction nvarchar(MAX),
AgencyID int,
Agent nvarchar(255),
Remark nvarchar(max),
EName nvarchar(255),
Paname nvarchar(255),
Cont nvarchar(255),
Depname nvarchar(255),
name nvarchar(255));
insert into #benefit_code21(id,
number,
pname,
collegeID,
applicationdate,
authorizedate,
lawState,
lawTime,
country,
category,
mainCategoryNumber
,allCategoryNumber,
typess,
levelss,
Introduction,
AgencyID,
Agent
,Remark
,EName
,Paname
,Cont
,Depname,name)
SELECT
Patent.ID,
Patent.Number,
Patent.Name,
Patent.CollegeID
, Patent.ApplicationDateTime
, Patent.AuthorizeDateTime
, Patent.LawState
, Patent.LawStateTime
, Patent.Country
, Patent.Category
, Patent.MainCategoryNumber
, Patent.AllCategoryNumber
, Patent.Type
, Patent.Level
, Patent.Introduction
, Patent.AgencyID
, Patent.Agent
, Patent.Remark
,Expert.Name
,PatentAgency.Name,
PatentAgency.Contract,
Department.Name,
STUFF(
(
SELECT ';' + CAST(name AS VARCHAR(MAX))
FROM dbo.PatentInventer
WHERE (Patent.ID = PatentInventer.PatentID)
FOR XML PATH ('')
)
,1,1,'')
AS NameValues
FROM dbo.PatentInventer ,dbo.Patent,Expert,PatentAgency,Department
where Patent.ID = PatentInventer.PatentID
and PatentAgency.ID=patent.AgencyID
and patent.CollegeID=Department.ID
and PatentInventer.ExpertID = Expert.ID
and PatentInventer.IsPrincipal = 'True'
GROUP BY Patent.ID,
Patent.Number,
Patent.Name,
Patent.CollegeID
, Patent.ApplicationDateTime
, Patent.AuthorizeDateTime
, Patent.LawState
, Patent.LawStateTime
, Patent.Country
, Patent.Category
, Patent.MainCategoryNumber
, Patent.AllCategoryNumber
, Patent.Type
, Patent.Level
, Patent.Introduction
, Patent.AgencyID
, Patent.Agent
, Patent.Remark
,Expert.Name
,PatentAgency.Name,
PatentAgency.Contract,
Department.Name select * from #benefit_code21; drop table #benefit_code21;

Sql Server 查询多行并一行的更多相关文章

  1. sql server 查询分析器消息栏里去掉“(5 行受影响)”

    sql server 查询分析器消息栏里去掉"(5 行受影响)"     在你代码的开始部分加上这个命令: set nocount on   记住在代码结尾的地方再加上: set ...

  2. SQL Server查询性能优化——堆表、碎片与索引(二)

    本文是对 SQL Server查询性能优化——堆表.碎片与索引(一)的一些总结.  第一:先对 SQL Server查询性能优化——堆表.碎片与索引(一)中的例一的SET STATISTICS IO之 ...

  3. SQL Server查询性能优化——覆盖索引(二)

    在SQL Server 查询性能优化——覆盖索引(一)中讲了覆盖索引的一些理论. 本文将具体讲一下使用不同索引对查询性能的影响. 下面通过实例,来查看不同的索引结构,如聚集索引.非聚集索引.组合索引等 ...

  4. 数据库表设计时一对一关系存在的必要性 数据库一对一、一对多、多对多设计 面试逻辑题3.31 sql server 查询某个表被哪些存储过程调用 DataTable根据字段去重 .Net Core Cors中间件解析 分析MySQL中哪些情况下数据库索引会失效

    数据库表设计时一对一关系存在的必要性 2017年07月24日 10:01:07 阅读数:694 在表设计过程中,我无意中觉得一对一关系觉得好没道理,直接放到一张表中不就可以了吗?真是说,网上信息什么都 ...

  5. 通过DBCC Page查看在SQL Server中哪行数据被锁住了?

    原文:通过DBCC Page查看在SQL Server中哪行数据被锁住了? 如何查看被锁的是哪行数据?通过dbcc page可以. 要想明白这个问题: 首先,需要模拟阻塞问题,这里直接模拟了阻塞问题的 ...

  6. [转] 利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能

    首先需要说明的是这篇文章的内容并不是如何调节SQL Server查询性能的(有关这方面的内容能写一本书),而是如何在SQL Server查询性能的调节中利用SET STATISTICS IO和SET ...

  7. 利用SET STATISTICS IO和SET STATISTICS TIME 优化SQL Server查询性能

    首先需要说明的是这篇文章的内容并不是如何调节SQL Server查询性能的(有关这方面的内容能写一本书),而是如何在SQL Server查询性能的调节中利用SET STATISTICS IO和SET ...

  8. 如何找出你性能最差的SQL Server查询

    我经常会被反复问到这样的问题:”我有一个性能很差的SQL Server.我如何找出最差性能的查询?“.因此在今天的文章里会给你一些让你很容易找到问题答案的信息向导. 问SQL Server! SQL ...

  9. Sql Server查询性能优化之走出索引的误区

    据了解绝大多数开发人员对于索引的理解都是一知半解,局限于大多数日常工作没有机会.也什么没有必要去关心.了解索引,实在哪天某个查询太慢了找到查询条件建个索引就ok,哪天又有个查询慢了,再建立个索引就是, ...

随机推荐

  1. thinkphp5.0 生命周期

    1.入口文件 // 应用入口文件 index.php // 定义项目路径 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 r ...

  2. Mac下eclipse导入其他工程中文注释出现乱码解决方案

    因为用的是mac版的eclipse,导入其他工程注释出现乱码的情况,找了网上的很多方法,大部分都是说的workspace,在这里修改,但是我修改之后还是乱码,最后发现这样一个方法,才得以解决. 点击 ...

  3. [转]hibernate缓存机制所有详解

    以下文章来自http://www.blogjava.net/tbwshc/articles/380013.html Hibernate 所有缓存机制详解 hibernate提供的一级缓存 hibern ...

  4. 毕业论文评审意见、导师意见范文、模板_Smile~风_百度空间

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  5. spring MVC 初探 (HelloWorld)

    1.使用spring MVC 需要导入相关jar包 2.web.xml 启用spring MVC <servlet> <servlet-name>spring3mvc</ ...

  6. CentOS7 开源跳板机(堡垒机) Jumpserver

    开源跳板机(堡垒机)Jumpserver 环境 CentOS 7   x64       关闭 selinux  firewalld jumpserver: 172.24.0.14 testserve ...

  7. CentOS 7 x64 安装 Ceph

    CentOS 7  x64 安装 Ceph 二, 实验环境 节点            IP                 主机名                  系统 MON         1 ...

  8. Linux下hosts、host.conf、resolv.conf

    /etc/resolv.conf 该文件是DNS域名解析的配置文件,它的格式很简单,每行以一个关键字开头,后接配置参数. resolv.conf的关键字主要有四个,分别是: nameserver   ...

  9. 用命令行使用soot反编译生成jimple

    使用工具:soot-2.5.0.jar 注意:soot-2.5.0.jar必须使用Java1.7以及之前的版本,使用Java1.8会发生错误. 修改jdk的方法是在设置java_home的路径的时候, ...

  10. 在阿里云ECS(CentOS6.5)上安装mysql

    首先查看服务器上是否已经安装过mysql 命令: rpm -qa | grep mysql 结果: 可以看到ECS上已经有mysql-libs这个包了.这并不影响安装. 查看yum服务器上提供的mys ...