﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Stephen Lasham / Article Discussions / Article Discussions by Author  / Extracting a String Within Delimeters - Part 2 / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 10:35:04 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>Thanks for the feedback.  The typo occurred in translation from the submitted MS/Word document to the HTML page and was an accident by the publisher that I did not pick up on.  Please accept my apologies for this.</description><pubDate>Tue, 14 Sep 2004 14:49:00 GMT</pubDate><dc:creator>Lashams</dc:creator></item><item><title>RE: Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>&lt;P&gt;drop table Sample_tableCREATE TABLE #Sample_table (Particulars varchar(120))GOINSERT INTO #Sample_table VALUES('LDR ; LUC20031026901 ; Vehicle')INSERT INTO #Sample_table VALUES('LDR ; Consolidated                                                     ')INSERT INTO #Sample_table VALUES('LDR ; SUB35030172701 ; Building')INSERT INTO #Sample_table VALUES('LDRR ; LIQ200310121 ; Liquor')&lt;/P&gt;&lt;P&gt;select * from #Sample_table&lt;/P&gt;&lt;P&gt;SELECT Particulars,--    quotename( -- enable this to see, that's just the string without spaces around      LTRIM(RTRIM(  SUBSTRING(Particulars,   /*from*/CHARINDEX(';',Particulars,1)+1,   -- search first delimiter and then offset 1 from first deliminter&lt;/P&gt;&lt;P&gt;   /* to */CHARINDEX(';',                    -- search for the next delimter as the end-of-string     SUBSTRING (Particulars,          /*from*/    (CHARINDEX (';', Particulars,1)+1) -- the first character after first delimiter         /* to */   , datalength(Particulars)     -- use datalength for not beeing bound to specific length         ) + ';'  -- for any case add a delimiter (this was a good idea from Denis Oliynik !!), if it's an additonal, it's just lost      ) - 1  -- delimiter Position minus one             )     ) -- rigth parenthesis for lrim       ) -- rigth parenthesis for rtrim--&amp;nbsp&lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt; rigth parenthesis for quotenameFROM #Sample_table&lt;/P&gt;&lt;P&gt;/* commet out ltrim/rtrim to extract the whole string with spacesThis is a very general select not delimited to programmed stringlenthes or varchar's etc. It just extracts the first delimited string within another string, not more or less.&lt;/P&gt;&lt;P&gt;sincerelyNorbert L.Muth, M.A.DBA of KNO-VA.de&lt;A href="mailto:Norbert.Muth@gmx.de"&gt;Norbert.Muth@gmx.de&lt;/A&gt;*/&lt;/P&gt;</description><pubDate>Mon, 13 Sep 2004 16:27:00 GMT</pubDate><dc:creator>Norbert L. Muth, M.A.</dc:creator></item><item><title>RE: Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>Wouldn't it be easier to just use:SELECT RIGHT(RTRIM(Particulars), LEN(RTRIM(Particulars)) - CHARINDEX(';',Particulars) - 1)FROM Sample_tableAlso, you could remove the RTRIMs if you used VARCHAR instead of CHAR...</description><pubDate>Mon, 13 Sep 2004 09:46:00 GMT</pubDate><dc:creator>Adam Machanic</dc:creator></item><item><title>RE: Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>&lt;P&gt;The innermost SUBSTRING will yield this:&lt;/P&gt;&lt;P&gt; LUC20031026901 ; Vehicle Consolidated SUB35030172701 ; Building LIQ200310121 ; Liquor&lt;/P&gt;&lt;P&gt;and when the semicolon is added, it will look like this:&lt;/P&gt;&lt;P&gt; LUC20031026901 ; Vehicle                                                                          ; Consolidated                                                                                      ; SUB35030172701 ; Building                                                                         ; LIQ200310121 ; Liquor                                                                             ;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 13 Sep 2004 08:01:00 GMT</pubDate><dc:creator>Code Monkey-158952</dc:creator></item><item><title>RE: Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>&lt;P&gt;There is a typo in the SELECT code, needs to be&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;SELECT Particulars,     LTRIM(RTRIM(SUBSTRING(       /* &amp;lt;text&amp;gt;&amp;gt; */ Particulars,       /* &amp;lt;start &amp;gt; */   CHARINDEX(';',Particulars,1) + 1,       /* &amp;lt;length&amp;gt; */   CHARINDEX(';',           SUBSTRING(Particulars, CHARINDEX(';', Particulars, 1) + 1, 99) + ';') - 1       ) ) ) AS Result_stringFROM Sample_table&lt;/P&gt;</description><pubDate>Mon, 13 Sep 2004 06:16:00 GMT</pubDate><dc:creator>Antares686</dc:creator></item><item><title>Extracting a String Within Delimeters - Part 2</title><link>http://www.sqlservercentral.com/Forums/Topic128292-176-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/slasham/extractingastringwithindelimeterspart2.asp&gt;http://www.sqlservercentral.com/colu</description><pubDate>Mon, 26 Jul 2004 16:49:00 GMT</pubDate><dc:creator>Lashams</dc:creator></item></channel></rss>