干货

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. Chapter 1 First Sight——1

    My mother drove me to the airport with the windows rolled down. 随着窗户渐渐摇下,我妈妈开着车送我去机场. It was seventy ...

  2. java实现webservice

    第一步:web工程--新建server-config.wsdd 文件与web.xml同级 其内容如下 <?xml version="1.0" encoding="U ...

  3. URL与String转换

    NSString *str = @"www.baidu.com"; NSURL *URL = [NSURL URLWithString:str];  //string>url ...

  4. Solr 按照得分score跟指定字段相乘排序

    sort=product([you_field],query($q)) desc

  5. linux获得目录下文件个数

    获得当前目录下文件个数赋值给变量panonum: panonum=$(ls -l |grep "^-" | wc -l) 获取指定目录下文件个数赋值给指定变量: panonum=$ ...

  6. git如何正确回滚代码

    git如何正确回滚代码 方法一,删除远程分支再提交 ①首先两步保证当前工作区是干净的,并且和远程分支代码一致 $ git co currentBranch $ git pull origin curr ...

  7. td文字过长部分显示,鼠标移动显示全部内容

    只要在该td中加上title属性,鼠标移到这里就会看到全部内容, 在td中加上div,属性设置如下,就能显示宽度为200px的内容,大于则隐藏.代码如下: <td title="我是代 ...

  8. 安卓 handler解析

    参考: 1.http://www.2cto.com/kf/201302/190591.html(安卓更新UI的两种方式,handler,Activity.runOnUIThread()) 2.http ...

  9. [题解]bzoj 1861 Book 书架 - Splay

    1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1396  Solved: 803[Submit][Stat ...

  10. Android动画之translate(位移动画)(转)

    转自:http://www.cnblogs.com/bavariama/archive/2013/01/29/2881225.html 上一篇文章讲了 Android的左右滑动切换,实现过程是非常简单 ...