I have a bunch of orderIds '1, 18, 1000, 77 ...' that I'm retreiving from a nvarchar(8000). I am trying to parse this string and put the id into a temporary table. Is there a simple and effective way to do this?
To view a list of all the orderIds that I parsed I should be able to do this:
select orderid from #temp
Give this a shot. It'll split and load your CSV values into a table variable.
Found and modified from Raymond at CodeBetter.
One-query solution:
Here is a UserDefined function that returns a DataTable with Id which you can use for your joins. Look at this article which addresses this case quite well.
Change the > to >= in the following code to work properly only on inputs with one comma. Credit to the first comment in the linked article.
The fastest way via a numbers table that takes seconds to create:
This is a great method I've been using for years based on the following article: http://www.sqlservercentral.com/articles/T-SQL/62867/
what do you think about this one?
http://swooshcode.blogspot.ro/2009/10/sql-split.html