Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql Split string function

CREATE FUNCTION [dbo].[Func_SplitString] 
( @Values VARCHAR(MAX)
, @splitStr VARCHAR(50)
)

RETURNS @Result_Table TABLE
       (
	     [value] nvarchar(MAX) NULL
       )
BEGIN
    DECLARE @TempStr nvarchar(MAX)
    WHILE (CHARINDEX(@splitStr,@Values)>0)
    BEGIN
        SET @TempStr=SUBSTRING(@Values,1,CHARINDEX(@splitStr,@Values)-1)
        INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
        SET @Values = REPLACE(@Values,@TempStr+@splitStr,'')
    END/*End While*/
	
    IF(LEN(RTRIM(LTRIM(@Values)))>0 AND CHARINDEX(@splitStr,RTRIM(LTRIM(@Values)))=0) 
    BEGIN
        SET @TempStr=@Values 
        INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
    End /*End IF*/
   RETURN 
END
Comment

SQL order by string split length

SELECT LEN(@String) - LEN(REPLACE(@String, ',', '')) + 1 
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql decimal remove trailing zeros 
Sql :: sql set data from a select query to a temp table and insert 
Sql :: cast in sql 
Sql :: postgress if 
Sql :: replace content value from old to new sql 
Sql :: how to recreate postgres database in docker 
Sql :: sqlalchemy get ids 
Sql :: oracle drop type if exists 
Sql :: sql cheat sheet 
Sql :: show specific events on mysql 
Sql :: SQL Primary Key multiple column 
Sql :: min mysql 
Sql :: insert data from one database table to another database table in postgresql using pgadmin 
Sql :: coalesce function in sql server 
Sql :: group by max date 
Sql :: not operator in sql 
Sql :: change sql global mode 
Sql :: php mysql select current month 
Sql :: postgresql find missing id 
Sql :: SQL Server modify_timestamp trigger 
Sql :: how to set all the time serveroutput on in oracle sql developer 
Sql :: create temp table sql 
Sql :: one to one and one to many relationship 
Sql :: oracle merge insert if not exists 
Sql :: postgresql insert multiple rows 
Sql :: update multiple rows 
Sql :: MySQL OR 
Sql :: how to put 0 or 000 depending IDCustomer length in sql server 
Sql :: convert minutes to hours in sql 
Sql :: sql order by 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =