crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

split function in sql
Question Posted on 25 Jun 2011Home >> DataBase >> SQL Query >> split function in sql

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[udf_Txt_SplitTAB]
(
@sInputList VARCHAR(8000)
, @Delimiter CHAR(1) = ','
)
RETURNS @List TABLE (Item VARCHAR(30)) WITH SCHEMABINDING
AS BEGIN
DECLARE @Item Varchar(30)
DECLARE @Pos int
, @NextPos int
, @LenInput int
, @LenNext int
, @DelimLen int
SELECT @Pos = 1
, @DelimLen = LEN(@Delimiter)
, @LenInput = LEN(@sInputList)
, @NextPos = CharIndex(@Delimiter, @sInputList, 1)
IF @Delimiter = ' ' BEGIN
INSERT INTO @List
SELECT 'ERROR: Blank is not a valid delimiter'
RETURN
END
While @Pos <= @LenInput and @NextPos > 0 BEGIN
IF @NextPos > @Pos BEGIN
SET @LenNext = @NextPos - @Pos
Set @Item = LTrim(RTrim(
substring(@sInputList
, @Pos
, @LenNext)
)
)
IF LEN(@Item) > 0
INSERT INTO @List SELECT @Item
END
SELECT @Pos = @NextPos + @DelimLen
, @NextPos = CharIndex(@Delimiter
, @sInputList
, @Pos)
END
SET @Item = LTrim(RTrim(
SUBSTRING(@sInputList
, @Pos
, @LenInput-@Pos + 1)
)
)
IF Len(@Item) > 0
INSERT INTO @List SELECT @Item
RETURN
END
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

How to get the table count in last used query from cache by sending tablename?

Write a SQL query to print 1 to 100 in sql server?

Sql Interview Latest Query questions asked on 30 dec 2020

nth highest number from table

some good sql query






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap