=
@ P
+
Len
(
@ Delimiter
)
-
1
End
Else
Begin
Break
End
End
Declare @ S Nvarchar ( 1000 ) If @ P = 0 And @ I = @ N Begin Set @ S = @ Expression End Else If @ I = @ N Begin Set @ S = Substring ( @ Expression , 1 , @ P - Len ( @ Delimiter )) End Return @ S End Usage: Code
Code highlighting produced by Actipro CodeHighlighter (
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 a platform, you find a custom sp
Example 1: obtain a string at a certain position in the string aa, dd, cc, rr, and fff. If the string is easily implemented through Split in C # or Java, however, the Split function is not directly provided in SQL Server.Of course
As we all know, in C #, it is easy to use the split method to divide a string into an array with the specified characters, but in T-SQL, it is .... In my project, there are the following applications: Read a batch of data in batches, then process the data in each row. After processing, return the processed ID and the failed ID to the database, this involves a bat
A string that requires a location in the string AA,DD,CC,RR,FFF is easily implemented in C # or Java by split, but there is no direct split function in SQL Server.
Of course, such problems can always be solved.
ALTER function [d
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 it. The following function implements string processing like an array.
Label:Database applications are often encountered where a field store connects key-value strings through delimiters, such as the following table in the filehistory structure column: Keywords We may convert in some business scenarios into the following forms: First, create a SQL function that splits the stitched string into a table CREATE FUNCTION [dbo].[uf_splitstringtotable](
@sInputList VARCHAR(MAX)
server|sqlserver| function
A function similar to split was written in SQL Server this morning, as required by query statistics, as follows
Create function F_split (@SourceSql varchar (8000), @StrSeprate varchar) returns @temp table (a varchar (100))-- function--date:2005-4-20--author for
Tags: return div function Insert Server OSI select nbsp dex CREATE FUNCTIONDbo. SPLIT (@Long_str NVARCHAR(MAX),@split_str NVARCHAR( -))
RETURNS @tmp TABLE(IDInT IDENTITY PRIMARY KEY, Short_strNVARCHAR(MAX)
)
as
BEGIN
DECLARE @short_str NVARCHAR(MAX),@split_str_length int,@split_str_Position_Begin int
SET @split_str_length = LEN(@split_str)
SET @Long_str=REPLACE(REPLACE(@
SET @dwIndex = CHARINDEX (@strSeparator, @strSource); --gets the position of the first delimiterWhile @dwIndex >0 BEGIN SET @strResult = LTRIM (RTRIM (@strSource, @dwIndex-1)); IF @strResult is NULL or @strResult = "or @strResult = @strSeparator BEGIN SET @strSeparator = SUBSTRING (@strSource, @dwI Ndex+1,len (@strSource) [email protected]); --the string to be manipulated removes the segmented part SET @dwIndex = CHARINDEX (@strSeparator, @strSource)
The script that implements the string Decomposition Method in SQL Server is as follows: Create Function [DBO]. [fn_splitstr] (@ sourcesql varchar (max), -- string @ strseprate varchar (10) -- Characters Used for decomposition) returns @ temp table (F1 varchar (100 )) as begin declare @ I int set @ sourcesql = rtrim (lt
server| Stored Procedures | paging
SQL Server Stored procedure paging, this issue has been discussed for several years, a lot of friends are asking me, so I would like to post my point of view
Create a table:
CREATE TABLE [TestTable] (
[ID] [int] IDENTITY (1, 1) not NULL,
[FirstName] [nvarchar] (MB) COLLATE chinese_prc_ci_as NULL,
[LastName] [nvarchar] (MB) COLL
Tags: blog http io ar using strong on file dataThe database is installed and the connection string is required for use in the program. How to write it? Take SQL Server R2 as an example.1, after installing SQL Server R2, similar to Oracle's Plsql tool.
SQL Server converts the data of a field into a string using a statement. SQL Server
For example, data column NameCopy codeThe Code is as follows:NameABCDFinal ResultCopy codeThe Code is as follows:A * B * c * d *
Declare @ test table (namevarchar (10 ))Insert into @ testva
Tags: models config string Pac-cin product MVC5 ArticlesThe Moviedbcontext class that you create is responsible for handling the tasks of connecting to the database and mapping the movie objects to database records. You may ask a question, how do you specify that it will connect to the database? In fact, you do not specify a database to use, and the Entity framework will use the default localdb. In this section, we will explicitly add the application'
can use servername/InstanceName as the data source to specify an SQL server instance.
Connect to an SQL server instance
The expression of the specified server instance is the same as the connection
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.