Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

CLR Funtion To split the cama separated string. Expand / Collapse
Author
Message
Posted Tuesday, September 25, 2012 12:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 2, 2014 1:34 AM
Points: 20, Visits: 150
Hi All,

I need a CLR function to split the "," separated string.

Ex: string like 1,2,3,4,

Result:

Value
----------
1
2
3
4

Thank’q
Post #1363808
Posted Tuesday, September 25, 2012 1:42 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 5,216, Visits: 5,108
Why do you need this to be in a CLR function?

There is a very good T-SQL function which you can find in my signature post by Jeff, but for ease of use here is the link http://www.sqlservercentral.com/articles/Tally+Table/72993/




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1363834
Posted Tuesday, September 25, 2012 4:02 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, May 2, 2014 1:34 AM
Points: 20, Visits: 150
I thought CLR function gives better performance on string functions, so that I am looking for CLR function.
Post #1363901
Posted Tuesday, September 25, 2012 4:04 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, June 27, 2014 8:03 AM
Points: 317, Visits: 1,079
Try this:

http://sqlblog.com/blogs/adam_machanic/archive/2009/04/28/sqlclr-string-splitting-part-2-even-faster-even-more-scalable.aspx
Post #1363907
Posted Tuesday, September 25, 2012 4:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 5,216, Visits: 5,108
If something can be done in SQL do it in SQL not CLR is my mantra.

String splitting can be done in either format, just depends on the load your putting through the splitter, there is a cut off point as with anything where performance vs values starts to go astray, the article details that at the bottom.

Have to remember that CLR uses memory from outside of the buffer pool, so if you already have a heavily loaded memory utilisation on the server, CLR may not be the best way to go.

Depends on the trade offs that you want.

Another one to look at http://www.pawlowski.cz/2010/10/fastest-csv-strings-splitting-using-clr-t-sql-vs-clr-revisited/




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1363909
Posted Wednesday, September 26, 2012 6:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 17, 2013 8:25 PM
Points: 1, Visits: 59
It's from a few years ago, but I've found Erland Sommarskog's entry on this to be the most comprehensive:

http://www.sommarskog.se/arrays-in-sql-2005.html#Split

We ended up using a modified version of his CLR function in our application. Sped things up a lot.
Post #1364632
Posted Wednesday, September 26, 2012 7:25 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 7:22 PM
Points: 20,680, Visits: 32,279
You will also find a clr string splitter in the discussion thread of Jeff's article linked above in a previous post. IIRC it is based on Adam Machanic's work.


Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1364660
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse