<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx</link><description>"hickymanz" asked in the SQL Server Central forums for a method of counting unique words in a text column. Wayne Lawton recommended using a string split function, which was a good idea, but not quite adequate for the job in my opinion. Typical string</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#2442</link><pubDate>Tue, 04 Sep 2007 23:26:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2442</guid><dc:creator>Chris Law</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;I have two tables within a SQL database. The 1st table has an identified column and column which lists one of more email identifers for a second table, &lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;ID &amp;nbsp; &amp;nbsp; Email&lt;/p&gt;
&lt;p&gt;-- &amp;nbsp; &amp;nbsp; ----------&lt;/p&gt;
&lt;p&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;AS1 AS11&lt;/p&gt;
&lt;p&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;AS2 AS3 AS4 AS5&lt;/p&gt;
&lt;p&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;AS6 AS7&lt;/p&gt;
&lt;p&gt;The second table has a column which has an email identifier and another column which lists one email address for that particular identifier, e.g.&lt;/p&gt;
&lt;p&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;EmailAddress&lt;/p&gt;
&lt;p&gt;--- &amp;nbsp; &amp;nbsp; ------------------&lt;/p&gt;
&lt;p&gt;AS1 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu@emc.com&lt;/p&gt;
&lt;p&gt;AS2 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu2@emc.com&lt;/p&gt;
&lt;p&gt;AS3 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu3@emc.com&lt;/p&gt;
&lt;p&gt;AS4 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu4@em.com&lt;/p&gt;
&lt;p&gt;AS5 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu5@emc.com&lt;/p&gt;
&lt;p&gt;AS6 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu6@emc.com&lt;/p&gt;
&lt;p&gt;AS7 &amp;nbsp; &amp;nbsp; &amp;nbsp;abcstu7@emc.com&lt;/p&gt;
&lt;p&gt;AS11 &amp;nbsp; &amp;nbsp; abcstu8@emc.com&lt;/p&gt;
&lt;p&gt;I need to create a stored procedure or function that:&lt;/p&gt;
&lt;p&gt;1. Selects an Email from the first table, based on a valid ID, &lt;/p&gt;
&lt;p&gt;2. Splits the Email field of the first table (using the space separator) so that there is an array of Emails and then,&lt;/p&gt;
&lt;p&gt;3. Selects the relevant EmailAddress value from the second table, based on a valid Email stored in the array&lt;/p&gt;
&lt;p&gt;Is there any way that this can be done directly within SQL Server using a stored procedure/function without having to use cursors? &lt;/p&gt;
&lt;p&gt;Many Thanks,&lt;/p&gt;
&lt;p&gt;Chris Law&lt;/p&gt;
&lt;p&gt;probetatester@yahoo.com&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#2514</link><pubDate>Mon, 10 Sep 2007 19:12:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2514</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Chris,&lt;/p&gt;
&lt;p&gt;Sure: Use a standard SplitString function (such as the one posted here: &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx" rel="nofollow" target="_new"&gt;http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx&lt;/a&gt;), and then use the following query:&lt;/p&gt;








&lt;p&gt;SELECT j.EmailAddress&lt;br&gt;FROM&lt;br&gt;(&lt;br&gt;SELECT x.OutParam&lt;br&gt;FROM YourIdentifierTable i&lt;br&gt;CROSS APPLY dbo.SplitString(i.Email) x&lt;br&gt;WHERE i.ID = 123&lt;br&gt;) y&lt;br&gt;JOIN YourEmailAddressTable j ON y.OutParam = j.ID&lt;/p&gt;</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#3576</link><pubDate>Thu, 29 Nov 2007 04:43:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3576</guid><dc:creator>Asghar</dc:creator><description>&lt;p&gt;Hi Adam this is a great function but I have got string with such as (&amp;quot;hello&amp;quot;,&amp;quot;sdfsfs&amp;quot;,....)&lt;/p&gt;
&lt;p&gt;My problem is how can I pass two parremeters such as , and &amp;quot;&amp;quot;.&lt;/p&gt;
&lt;p&gt;and how can I insert the values into a table&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#3674</link><pubDate>Tue, 04 Dec 2007 15:32:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3674</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Asghar:&lt;/p&gt;
&lt;p&gt;I think you need the Tokenizer (or perhaps a slight modification of it):&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/tokenize-udf.aspx"&gt;http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/tokenize-udf.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#8786</link><pubDate>Mon, 08 Sep 2008 12:36:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:8786</guid><dc:creator>Phani Kumar</dc:creator><description>&lt;p&gt;Hi adam i am doing a search engine for my job portal... if user wnters a search string i have to give him related records using rank technology.. can you suggest me .how to pass a full string to a querry it should be matched by all columns and give me results.. &lt;/p&gt;
&lt;p&gt;ex: search string is .. i want jobs on c in alabama&lt;/p&gt;
&lt;p&gt;i have to sarch this string in posting table&lt;/p&gt;
&lt;p&gt;can you give me example please&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#13300</link><pubDate>Wed, 15 Apr 2009 09:02:19 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13300</guid><dc:creator>shiburaj</dc:creator><description>&lt;p&gt;Hi Chris Law, &lt;/p&gt;
&lt;p&gt;I had a similar requirement, &lt;/p&gt;
&lt;p&gt; The query I used was &lt;/p&gt;
&lt;p&gt;select &lt;/p&gt;
&lt;p&gt;	t2.userprofile_empcompid, &lt;/p&gt;
&lt;p&gt;	t2.userprofile_empid, &lt;/p&gt;
&lt;p&gt;	t1.email,&lt;/p&gt;
&lt;p&gt;case when CHARINDEX ( '@' ,t1.email ) &amp;gt;0 then&lt;/p&gt;
&lt;p&gt;	left(t1.email,(CHARINDEX ( '@' ,t1.email &amp;nbsp;)-1)) else t1.email end a &amp;nbsp;,	&lt;/p&gt;
&lt;p&gt;	t2.userprofile_emailadd	 &lt;/p&gt;
&lt;p&gt;from EPHR_Email t1&lt;/p&gt;
&lt;p&gt;INNER JOIN userprofile t2&lt;/p&gt;
&lt;p&gt;ON t1. CompId = t2.userprofile_empcompid&lt;/p&gt;
&lt;p&gt;AND t1.EmpId = t2.userprofile_empid&lt;/p&gt;
&lt;p&gt;hope it helps.&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#16235</link><pubDate>Mon, 24 Aug 2009 03:20:10 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16235</guid><dc:creator>Ngl</dc:creator><description>&lt;p&gt;Please help me, how to insert the result of split function?&lt;/p&gt;
&lt;p&gt;Eg.&lt;/p&gt;
&lt;p&gt;The result of split function is :&lt;/p&gt;
&lt;p&gt;Item&lt;/p&gt;
&lt;p&gt;=====&lt;/p&gt;
&lt;p&gt;001&lt;/p&gt;
&lt;p&gt;Items2&lt;/p&gt;
&lt;p&gt;55&lt;/p&gt;
&lt;p&gt;I wanna insert the result above to table tbl_data(code,name,qty).&lt;/p&gt;
&lt;p&gt;How can I do that?&lt;/p&gt;
&lt;p&gt;Thanx&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#16247</link><pubDate>Mon, 24 Aug 2009 16:24:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16247</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Ngl,&lt;/p&gt;
&lt;p&gt;You'll have to pivot the results--using either the PIVOT function or CASE expressions. Google &amp;quot;sql crosstab&amp;quot; for a number of solutions.&lt;/p&gt;
</description></item><item><title>re: Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/pattern-based-split-string.aspx#24630</link><pubDate>Wed, 28 Apr 2010 06:55:02 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:24630</guid><dc:creator>Mohan Goud</dc:creator><description>&lt;p&gt;Hi NGL,&lt;/p&gt;
&lt;p&gt;My requirement is how to split the strings in sqlserver 2005.&lt;/p&gt;
&lt;p&gt;for example:&lt;/p&gt;
&lt;p&gt;Vtable[Table Name]&lt;/p&gt;
&lt;p&gt;Fname[column Name varchar(60)]&lt;/p&gt;
&lt;p&gt;Aamina Yuusuf Dudub Bashiir----&amp;gt; Split this word as follows&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Aamina&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yuusuf &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dudub &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bashiir&lt;/p&gt;
</description></item></channel></rss>