Solution for the QlikView, Biztalk, DotNet and MSBI real time development problems
Search This Blog
Monday, July 18, 2011
Split function in sql server 2005/2008
GO
CREATE FUNCTION dbo.fnSplit(
@sInputList VARCHAR(8000) -- List of delimited items
, @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items
) RETURNS @List TABLE (item VARCHAR(8000))
BEGIN
DECLARE @sItem VARCHAR(8000)
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
BEGIN
SELECT
@sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))
IF LEN(@sItem) > 0
INSERT INTO @List SELECT @sItem
END
IF LEN(@sInputList) > 0
INSERT INTO @List SELECT @sInputList -- Put the last item in
RETURN
END
GO
Example :
SELECT * from fnSplit('1,2,3,4,5',',')
Labels:
Sql Server
Subscribe to:
Post Comments (Atom)
Popular Posts
-
The typical way of testing WCF services is to create a test project, add a service reference to the project, and then write a test agains...
-
why use Windows Workflow Foundation? Microsoft has provided this foundation in order to simplify and enhance your .NET development. It is n...
-
Qlikview developer, Designer and admin interview questions (Qlikview developer, Designer and admin FAQ’S) 1. Difference between Set ...
-
Within a class, const , static and readonly members are special in comparison to the other modifiers. const vs. readonly const ...
-
BizTalk Developer Interview Questions and Answers : Schema 1. What is the purpose of a document schema? The schema is basically a contr...
No comments:
Post a Comment