SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Split and concatenate function


Split and concatenate function

Author
Message
Tomaz Kastrun
Tomaz Kastrun
Say Hey Kid
Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)Say Hey Kid (703 reputation)

Group: General Forum Members
Points: 703 Visits: 756
Comments posted to this topic are about the item Split and concatenate function

Tomaž Kaštrun | twitter: @tomaz_tsql | blog: https://tomaztsql.wordpress.com/
ui ranejeb
ui ranejeb
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 130
My favorite one:
http://sqlhint.com/sqlserver/sqlserver/how-to/best-split-function-tsql-delimited
Luis Cazares
Luis Cazares
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52413 Visits: 20026
The best splitter for T-SQL is right here along with several tests. It will outperform any splitter using while loops or xml.

With it, you can replace your function to this. Note that it has a limit to 4000 unicode chars (8000 for non-unicode) to avoid the use of large data types and improve performance.


-- Split and concatenate back to string
CREATE FUNCTION [dbo].[Split_and_concatenate]
(
@str NVARCHAR(4000)
,@delimiter CHAR(1)
)
RETURNS NVARCHAR(8000)
AS
BEGIN
SELECT STUFF( (SELECT '; ' + CASE Item WHEN '1' THEN '11'
WHEN '2' THEN '22'
ELSE '33' END
FROM dbo.[DelimitedSplitN4K](@str, @delimiter)
FOR XML PATH('')),1,2, '')




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search