SQL Server implements the split function to split strings and Its Usage example. sqlsplit
This article describes how to use SQL Server to split strings using the split function. We will share this with you for your reference. The details are as
function | string T-SQL is less capable of handling strings, such as I'm looping through strings like 1,2,3,4,5, and if you use arrays, traversal is simple, but T-SQL does not support arrays, so it's tricky to handle. The function below implements
This article illustrates the function and usage of SQL Server to implement Split function split string. Share to everyone for your reference, specific as follows:
/*
function Name: F_splittonvarchar function
: To realize the function of Split
In the recent project development process, encountered SQL Server automatically split the monthly function requirements, here online collation of information.
1, why the need for custom split month
Today, when you comb through all the functions of
1 The rise of database splittingIn the past few years, the concept of database splitting has become more and more popular with the large increase of business application database transaction volume and the increase of database size. The success of
Summary of several methods for implementing the SPLIT function in SQL (required), sqlsplit
Example 1
The Code is as follows:
Create function f_split (@ SourceSql varchar (8000), @ StrSeprate varchar (10) returns @ temp table (a varchar (100) --
Example 1
The code is as follows
Create function F_split (@SourceSql varchar (8000), @StrSeprate varchar)
returns @temp table (a varchar (100))
--function of the split function
--date:2003-10-14
as
begin
Declare @i int
set @SourceSql
SQL to the string processing capabilities are relatively weak, such as I want to loop traversal like 1, 2, 3, 4, 5 such strings, if the use of arrays, traversal is very simple, but the T-SQL does not support the array, so it is troublesome to handle
One, using a temporary table as an array
Copy Code code as follows:
Create function F_split (@c varchar), @split varchar (2))
Returns @t table (col varchar (20))
As
Begin
while (CHARINDEX (@split, @c) <>0)
Begin
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.