当前位置:网站首页>String in SQL Server_ Implementation of split function
String in SQL Server_ Implementation of split function
2022-07-23 07:15:00 【Lazy Ethan】
Summary
SQL Server stay 2016 The version supports STRING_SPLIT Method , String can be divided into delimiters , Cut into a data sheet , Easy to use . however SQL Server 2016 Previous versions did not have this method . This passage SQL Server To implement this method .
Source code and implementation
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fn_Split]
(@input nvarchar(max), @separater char(1))
RETURNS
@result TABLE (
value nvarchar(max) not null
)
AS
BEGIN
declare @tmp nvarchar (max)
declare @EndIndex int
SET @input = @input + @separater
WHILE LEN(@input) > 0
BEGIN
SET @EndIndex = CHARINDEX(@separater, @input)
SET @tmp = SUBSTRING(@input, 1, @EndIndex - 1);
IF LEN(@tmp) > 0
INSERT INTO @result SELECT @tmp
SET @input = SUBSTRING(@input, @EndIndex+1, LEN(@input)- @EndIndex)
END
RETURN
END
GO
- Method accepts two parameters , The first is the string to be split , The other is the separator , Separator only 1 position ;
- Method returns a table valued variable , This variable has only one column value;
- For the convenience of string processing , Append the delimiter to the end of the string to be split ;
- Find the position of the first separator in the string to be split , Insert the contents before the delimiter into the table variable , Delete the separator and the string before the separator from the string to be split , Until the string to be split is empty ;
- Return table variables .
Method call
This method returns a table valued function , So we need to put from After clause
select * from dbo.fn_Split('a,b,c',',')
This method ignores null values , The following string will only return a b c Three pieces of data .
select * from dbo.fn_Split('a,b,c,,',',')
边栏推荐
- Esphone's self-made infrared remote control is connected to ha to control lights, switches, etc. any remote control can be used
- [matlab project practice] analysis of spatial and temporal characteristics of drought in a region based on SPI index
- 用于图像语义分割的GAU与PPM
- MySql的DDL和DML和DQL的基本语法
- Q6ui layout operation
- 电脑一拖二显示器分辨率怎么调? 两个显示器设置不同分辨率的技巧
- Microsoft, how can't we upload photos? What's the matter? The solution of twinsornot photos not being transmitted
- Unity 笔记——Addressables的使用
- 为什么不能隐藏文件夹?电脑隐藏的文件夹还能看到的解决办法
- LAN SDN technology hard core insider - 3 prequel breaks through the bottleneck of multi-core virtualization
猜你喜欢

After the applet wx.setstoragesync, sometimes it can't get data with getstoragesync

The ability to detect movement in vivo and build a safe and reliable payment level "face brushing" experience

小黑啃leetcode:589. N 叉树的前序遍历

【高并发基石】多线程、守护线程、线程安全、线程同步、互斥锁

Database system design: partition

Image processing solution veimagex technology evolution Road

【FAQ】应用内支付服务无法拉起支付页面常见原因分析和解决方法

Realize OPC UA publish/subscribe single send

threejs+shader绘制常用的图形

Q6ui布局操作
随机推荐
How to adjust the resolution of the computer with two monitors? Skills of setting different resolutions for two monitors
再学电商项目之谷粒商城之ES6新特性
局域网SDN技术硬核内幕 - 02 前传 多核技术为摩尔定律续一秒
[C# 数组]-C# 之中的一维数组和对象数组
How to do if the control panel program cannot be uninstalled? Compulsory uninstallation software tutorial
How to quickly shut down the computer shut down command sharing
AE common expression summary "suggestions collection"
电脑屏幕发黄怎么回事 显示器屏幕发黄是什么原因及排查方法
电脑如何快速关机 电脑关机命令分享
电脑不能截屏怎么办?电脑的快捷截屏键无法使用的解决办法
软件卸载不掉 显示请等待当前程序完成卸载或更改的解决办法
cpu温度多少正常 cpu长期100度会烧吗
小马激活工具出现Cannot open file k:\OEMSF 的解决方法
How to solve the problem that telnet is not an internal or external command? Telnet is not an internal or external command solution
What if the file copied by SSD is only dozens of KB? Solution to slow copying speed after installing hard disk in computer
百度钱包帮你还信用卡 跨行还款0手续费 实时到帐 新人奖励5元
[matlab project practice] sine sweep (sine sweep signal)
分享一个qt实现的登录界面模板
What is the difference between 32-bit and 64 bit computers
【ARC127F】±AB