当前位置:网站首页>SQL Server stuff and for XML path
SQL Server stuff and for XML path
2022-07-28 18:35:00 【Cang jiuxiao Hai】

Required press type After group query , Put the same type Of ,name Merge column values , Achieve the following results :

The analysis is as follows :
One 、FOR xml path
FOR XML PATH Some may know, some may not know , Actually It is to query the result set with XML Formal display , With it, we can simplify our query statements and realize some work that may need to be completed with the help of functions or stored procedures . Let's take an example .
Suppose there is a query table as follows

sql One :
select type,name from tb_account where name like '% Test induction %' FOR xml path Query results <row> <type>0</type> <name> Test login </name> </row> <row> <type>1</type> <name> Test induction 6</name> </row> <row> <type>0</type> <name> Test induction </name> </row>sql Two :
select type,name from tb_account where name like '% Test induction %' FOR xml path('')Query results :
<type>0</type> <name> Test login </name> <type>1</type> <name> Test induction 6</name> <type>0</type> <name> Test induction </name>
sql 3、 ... and :
select type,name from tb_account where name like '% Test induction %' FOR xml path('root')Query results :
<root> <type>0</type> <name> Test login </name> </root> <root> <type>1</type> <name> Test induction 6</name> </root> <root> <type>0</type> <name> Test induction </name> </root>sql Four :
select 10+type,','+name+',' from tb_account where name like '% Test induction %' FOR xml path('')Query results
10, Test login ,11, Test induction 6,10, Test induction ,
Two 、stuff functionstuff(param1, startIndex, length, param2)
explain : take param1 Zhongzi startIndex(SQL It's all from 1 Start , Instead of 0) rise , Delete length Characters , And then use param2 Replace deleted characters .remarks
If the start position or length value is negative , If the length of the string is greater than the first position , Will return an empty string . If the length to be deleted is greater than the length of the first string , Will delete the first character in the first string .Example
The following example is in the first string abcdef Delete from section 2 A place ( character b) The first three characters , Then insert a second string at the beginning of the deletion , To create and return a string .SELECT STUFF('abcdef', 2, 3, 'ijklmn');
GOHere's the result set :
---------
aijklmnef
边栏推荐
- Novice record: some small knowledge of mechanical keyboard
- Detailed explanation of network RJ45 interface
- #夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)
- Msg.value of solidity
- 低码在数字化转型中扮演什么角色?
- Dormant for two years! Lingsheng technology's first aiot chip released: Samsung 11nm process, integrated NPU core!
- C WPF normal project suddenly prompts that the name "initializecomponent" does not exist in the current context
- Brief introduction to the principle of spectrometer I
- Live broadcast starrocks technology insider: low base global dictionary optimization
- 示波器参数详解
猜你喜欢

#夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)

What role does low code play in the digital transformation?

示波器简介

网络RJ45接口详解

ADS仿真 之 交流仿真和S参数仿真示例

互联智能,如何定义下一代网络变革

物联网在智慧城市的应用

Centos8 uses docker to install WordPress in wordpress+mysql configuration file_ DB_ Understanding of host

实验楼----PHP大法

Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
随机推荐
haproxy实现代理配置
Go语言系列之日志库zap
数字化转型中的DevOps——弹性合作
互联智能,如何定义下一代网络变革
solidity的msg.value
Dormant for two years! Lingsheng technology's first aiot chip released: Samsung 11nm process, integrated NPU core!
Detailed explanation of oscilloscope parameters
Video Number Xiaobai starting operation guide
Advanced Design System(ADS)2009 射频仿真入门
深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析
The revenue of Shanghai silicon industry in the first half of the year was 850million yuan, an increase of 30.53% year on year! Various product certifications are accelerating
Implementation of solid transfer function (based on transfer)
网络RJ45接口详解
电源适配器 全球定义
Golang并发模型之
Introduction to advanced design system (ads) 2009 RF simulation
iptables 配置
What role does low code play in the digital transformation?
Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)
solidity的modifier修饰器的_;