ALTER FUNCTIONDbo.fn_split (@Expression VARCHAR(8000), @Delimiter VARCHAR(Ten))RETURNS @table_Value TABLE(SortnoINT IDENTITY(1,1) not NULL, ValueVARCHAR( -) COLLATE SQL_Latin1_General_CP1_CI_ASDEFAULT "') asBEGIN --============ DECLARE LOCAL VARIABLE to use =============================== DECLARE @intEndpos BIGINT DECLARE @strTemp VARCHAR( -) --============ INITIALIZE The VALUE of VARIABLE ============================== SET @intEndpos = 0 SET @strTemp = "
Tags: string conversion character name number keyword function execution injection stringIn SQL Server, a string that is separated by a comma "," is converted to a table and applied with the in condition Select from where inch (1,2,3) Such statements and commonly used, but if in the next one of the next-to-last is a v
Label:F_split: Splitting a string into a data table CreateFUNCTION[Dbo].[F_Split](@SplitStringnvarcharMax),--SOURCE string@Separatornvarchar10)=‘‘--delimited symbols, default to spaces)RETURNS@SplitStringsTableTABLE--Data table for Output([Id]IntIdentity1,1),[Value]nvarcharMax) )AsBEGINDECLARE@CurrentIndexInt;DECLARE@NextIndexInt;DECLARE@ReturnTextnvarcharMax);S
Stored Procedures | Strings I was working on a project to study the technology of querying multiple keywords, which is one of the techniques used.The role of the "delimited string" stored procedure is to save the string of the "Jiangjs,shenxy,cheng" class to a table. CREATE PROCEDURE [Delimited
Copy Code code as follows:
eclare @str nvarchar (50);
Set @str = ' 462,464,2 ';
Select @str as ' string '
Select Len (@str) as ' character length '
Select Charindex (', ', @str, 1) as ' the index value of the first comma '
Select Left (@str, charindex (', ', @str, 1)-1) as ' first value '
Select SUBSTRING (@str, charindex (', ', @str, 1) +1,len (@str)) as ' to intercept the trailing
Sql-function Create function Database output results are separated by commas, and in development there are also many arguments passed in the form of comma-string arguments (not recommended when data is large).
For example: Find the name "John, Li II" data in the database at this time to do this parameter processing as shown:
The function code is as follows
Label: string AA="1,2,3";
String Sqltxt="Select*from thewhere in ("+ AA+")"; It is possible to convert a string such as "one-way" to a temporary table with one column, 3 rows, and one item in each row (separated by commas) This function can be written like this: GO
/** * * * object:userdefinedfunction [dbo]. [Strto
Question: How do I get Elements in comma-separated string data in a T-SQL?Answer:1. extracts string elements one by one using loops. you can obtain the number of elements in the string and the two functions of the elements at the specified cable by using the preceding settin
Tags: length des. com object RIP Color COM technology share delimiter Select STUFF ((select ',' + modifyby
from dbo.tbl_stationprofile
for
XML PATH (")
11") as Name Comma-separated string-to-table Use [Mbg3sdb] GO/** * * * object:userdefinedfunction [dbo]. [Getidlist] Script DATE:2017/9/12 10:13:38 * * * * **/SET ANSI_NULLS on Go SET
After SQL-function is created, the output results of the function database are separated by commas (,). During Development, many parameters with comma (,) are passed in as parameters (this is not recommended when data is large)
For example, search for data with the name "Zhang San, Li 'er" and process this parameter in the database.
FunctionCodeAs follows:
View code
Create Function [ DBO
Usage scenarios:For example, you need to query all student numbers with scores greater than 95, separated by commas into a string, from the Student score table.To prepare the test data:CREATE TABLE score (ID int,score int)INSERT into score values (1,90)INSERT into score values (2,96)INSERT into score values (3,99)It is now necessary to query the result string "2,,3" with a single statement.The
Concatenate multiple rows of records in the same column in Oracle into a string [SQL] -- raw data -- a 111 -- B 222 -- a 333 -- a 444 -- B 555 -- final result -- a 111*333*444 SELECT L4.L _ TIME, MAX (SUBSTR (L4. group CONTENT, 2) final field value FROM (SELECT L3.L _ TIME, SYS_CONNECT_BY_PATH (L3.L _ CONTENT ,'*') AS group content from (SELECT L2.L _ TIME, L2.L
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.