Often we want to use the bulk operation will be used to split the string, the sad is that SQL Server does not have a split function, so we can only do it ourselves to solve. In order to reduce the number of communications with the database, we will use this method to achieve
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
Specific ways to split string functions in a SQL Server database:
CREATE FUNCTION uf_strsplit ' 1.1.2.50 ', '. '(@origStr varchar (7000),--the string to be split@markStr varchar (100))--split
Tags: http technology present tar comma Ace SEL Reference codeToday to change to the old man's code, actually put multiple IDs in a column, or use the comma partition ... What do you do when you inquire???Search the internet for half a day, finally found a SQL Server inside there is a parsename function, you can press. (dot) to split the
Label:SQL Server Split stringThe following is a function that creates a split string with ",":createfunctionf_splitstr (@SourceSql varchar (8000), @ Strsepratevarchar (+)) returns @temp table (F1varchar) as begindeclare @ch asvarchar (set@[email) Protected][emailprotected]while (@SourceSql
Label:Use [DataChange]
GO
/****** Object: userdefinedfunction [dbo].[ F_SPLITSTR] Script date:05/09/2016 15:04:21 Apply SQL: Implement data segmentation such as data: b41j-002/145%b41j-002/15%b41j-003/36%b41j-000/00%b43k-001/00%b41j-002/045%b41j-002/055%b41j-002/21%b43k-008/00 %b81b-007/04%b43k-029/00%b43k-027/00%b43k-029/093 Take the previous digit in each set of% data together to get the data in% split
is only necessary to use the default keyword.2 Select * fromSplit (default,'123,456,789')3 4 Select * fromSplit (default,'123,456,789,')5 6 --Try other character segmentation below7 Select * fromSplit ('ABC','11111abc22222abc33333')8 9 Select * fromSplit ('ABC','11111ABC22222ABC33333ABC')The disadvantage is that you cannot directly act on a table, and you cannot support multi-character segmentation at the same time.Of course, if more than a few parameters, but also reluctantly, but I would
--Description: Splitting a string function--SELECT * FROM dbo. Split (' a,b,c,d,e,f,g ', ', ')-- =============================================CREATE FUNCTION [dbo].[Split](@Text VARCHAR(8000) ,@Sign NVARCHAR(4000) ) RETURNS @tempTable TABLE(IDINT IDENTITY(1,1)PRIMARY KEY,[TempVal] VARCHAR(4000) ) as BEGIN DECLARE @StartIndex INT --where to start looking D
SelectValue fromTf_njvalues ('3c457a2d-188b-4d99-a822-2968054e1fb8,3c457a2d-188b-4d99-a822-2968054e1fb8')CREATE FUNCTIONTf_njvalues (@P0 varchar(Max)--characters that need to be intercepted) RETURNS @OUT_TABLE TABLE(ValueVARCHAR(Max)) as BEGIN DECLARE @SQL varchar(Max), @output varchar( -) Set @P0= Case when Right(@P0,1)=',' Then @P0 Else @P0+',' End while CHARINDEX(',',@P0)>0 begin Set @output=left(@P0,CHARINDEX(',',@P0)-1) I
Tags: substring ret div character Zid insert case when tab substrCREATE FUNCTION Dbo.sf_ds_splitnvarchar(@strValues nvarchar (4000))RETURNS @tblStrList TABLE (id int identity (), value nvarchar (4000))AsBEGINdeclare @strTmp nvarchar (4000)DECLARE @intPos intSelect @strValues =ltrim (RTrim (@strValues))While @strValues BeginSelect @intPos =case when charindex (', ', @strValues) =0 then Len (@strValues) Else charindex (', ', @strValues)-1 endSelect @strTmp =ltrim (RTrim (substring (@strValues, 1,
Original: "SQL" SQL version of the Split function. Used to split a string into a single-column tableFunctionality is similar to the. NET version of the String.Split function, except that. NET returns an array, which returns a single-column table with one row for each
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 the processing of strings like an array.
First, use a temporary table as an array create function f_split (@c varchar
See a post in the forum, the post has some SQL aspects of the question, I think these questions are very representative.The connection of the original posts is: http://bbs.csdn.net/topics/390884161?page=1#post-398177057Here is my solution, for your reference:1. Splitting stringsCREATE TABLE test1 (number varchar) INSERT into test1 values (' 1,2,3,4,5,6 ') desired result: number------123456 (6 rows affected)My Solution:--1.
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.