I have a SQL Server 2008 R2 column containing a string which I need to split by a comma. I have seen many answers on StackOverflow but none of them works in R2. I have made sure I have select permissions on any split function examples. Any help greatly appreciated.
相关问题
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
- Get path of node in tree
- How to evaluate an input in the WHERE clause
- Delete all records in table which have no referenc
相关文章
- How to truncate seconds in TSQL?
- Code for inserting data into SQL Server database u
- SQL Server 2008 Change Data Capture, who made the
- How do we alias a Sql Server instance name used in
- SQL identity (1,1) starting at 0
- How to do a UNION on a single table?
- SQL Group by Count of Counts
- SQL Server drop and recreate indexes of a table
I needed a quick way to get rid of the
+4
from a zip code.No proc... no UDF... just one tight little inline command that does what it must. Not fancy, not elegant.
Change the delimiter as needed, etc, and it will work for anything.
A solution using a CTE, if anyone should need that (apart from me, who obviously did, that is why I wrote it).
With all due respect to @AviG this is the bug free version of function deviced by him to return all the tokens in full.
if you replace
with
you can eliminate that last insert after the while loop!
All the functions for string splitting that use some kind of Loop-ing (iterations) have bad performance. They should be replaced with set-based solution.
This code executes excellent.
This is more narrowly-tailored. When I do this I usually have a comma-delimited list of unique ids (INT or BIGINT), which I want to cast as a table to use as an inner join to another table that has a primary key of INT or BIGINT. I want an in-line table-valued function returned so that I have the most efficient join possible.
Sample usage would be:
I stole the idea from http://sqlrecords.blogspot.com/2012/11/converting-delimited-list-to-table.html, changing it to be in-line table-valued and cast as INT.