﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 Integration Services  / how to use substring to get the values in bold / 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>Tue, 21 May 2013 02:30:38 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: how to use substring to get the values in bold</title><link>http://www.sqlservercentral.com/Forums/Topic1385894-148-1.aspx</link><description>Here's a method to parse the string by using a second delimited string of the keywords themselves used as the delimiting values. The strings are split using the DelimitedSplit8K function.[code="sql"]DECLARE    @S VARCHAR(MAX)   ,@Split CHAR(1)   ,@KeyWords VARCHAR(50)SET @Split = ' 'SELECT    @S = 'Collapsed Statue: Matured Life # 007812 between BOKSAM KAND LAMOG and Bill APPER SRIM (Goper)'    ,@KeyWords = 'between,and,(Goper)'        --other variations for testing    --@S = 'Collapsed Statue: XXXX YYYYY Matured Life # 007812 between BOKSAM KAND LAMOG and Bill APPER SRIM (Goper)'    --,@KeyWords = 'Statue:,between,and,(Goper)'    --@S = 'Collapsed Statue: Matured Life # 007812 between BOKSAM KAND LAMOG and Bill APPER SRIM (Goper) XXXX YYYYY'    --@S = 'Collapsed Statue: Matured Life # 007812 between BOKSAM ZZZZZ KAND LAMOG and Bill YYY APPER SRIM (Goper) XXXX YYYYY'    --,@KeyWords = 'Collapsed,YYYYY'    --,@KeyWords = '#,and,(Goper)' IF OBJECT_ID('tempdb..#TempTable') IS NOT NULLDROP TABLE #TempTableCREATE TABLE #TempTable (    [n1] INT NOT NULL,    [i1] VARCHAR(50) NULL,    [n2] INT NULL,    [i2] VARCHAR(50) NULL,    PRIMARY KEY (n1))INSERT INTO #TempTableSELECT     dsk1.ItemNumber AS n1   ,dsk1.Item AS i1   ,dsk2.ItemNumber AS n2   ,dsk2.Item AS i2FROM     dbo.tvfDelimitedSplit8K(@S,' ') AS dsk1LEFT OUTER JOIN     (    SELECT         Item        ,ItemNumber    FROM        dbo.tvfDelimitedSplit8K(@KeyWords,',')    ) AS dsk2    ON dsk1.Item = dsk2.Item    SELECT   t1.i1 AS itemFROM     #TempTable AS t1INNER JOIN     #TempTable AS t2    ON t2.n1 = (SELECT n1 FROM #TempTable WHERE n1 &amp;gt; 0 GROUP BY n1 HAVING MIN(n2)=1)INNER JOIN     #TempTable AS t3    ON t3.n1 = (SELECT n1 FROM #TempTable WHERE n1 &amp;gt; 0 GROUP BY n1 HAVING MAX(n2)=(SELECT COUNT(n2) FROM #TempTable))WHERE    t1.n1 &amp;gt; t2.n1    AND t1.n1 &amp;lt; t3.n1    AND t1.n2 IS NULL[/code]</description><pubDate>Mon, 19 Nov 2012 20:55:06 GMT</pubDate><dc:creator>Steven Willis</dc:creator></item><item><title>RE: how to use substring to get the values in bold</title><link>http://www.sqlservercentral.com/Forums/Topic1385894-148-1.aspx</link><description>You also need to ensure that 'between', 'and' and '(' cannot appear in the text you are trying to extract.I'd suggest doing this in stages to facilitate future maintenance.Definitely as has already been suggested obtain the string indices first - then check in case those terminators are not present.If there can be more than one instance then you probably will find it easier to follow the code if you store intermediate substrings in some working variables. That way you can look for the first or last instance of each and discard anything before the first or after the last.e.g. you go fromCollapsed Statue: Matured Life # 007812 between BOKSAM KAND LAMOG and Bill APPER SRIM (Goper)everything after first 'between 'BOKSAM KAND LAMOG and Bill APPER SRIM (Goper)everything before last ' ('BOKSAM KAND LAMOG and Bill APPER SRIMnow you just need to worry about the ' and ' - how you handle that will depend whether ' and ' can appear in either string.If it can appear in the first section but not the second take everything before the last ' and ' and everything after the last one.If it can appear in the secondsection but not the first take everything before the first ' and ' and everything after the first one.If it can't appear in either - use whichever of the above is easier.If it can appear in both you will need to find some other way to identify the text you want..</description><pubDate>Mon, 19 Nov 2012 05:19:35 GMT</pubDate><dc:creator>crmitchell</dc:creator></item><item><title>RE: how to use substring to get the values in bold</title><link>http://www.sqlservercentral.com/Forums/Topic1385894-148-1.aspx</link><description>The problem you're likely getting is invalid values for the start or length of the SUBSTRING.Find the start value and length first and then test it to see if it's valid.  If it is, then conditionally use it to do the SUBSTRING.</description><pubDate>Sun, 18 Nov 2012 09:54:06 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>how to use substring to get the values in bold</title><link>http://www.sqlservercentral.com/Forums/Topic1385894-148-1.aspx</link><description>Hello All,Could you please tell me how to get the value after 'between', before 'and'  i.e., BOKSAM KAND LAMOG  also after 'and' and before '('want to get the bold values (between, and are case senstive)for example MatterColumn   has value  "Collapsed Statue: Matured Life # 007812 between [b]BOKSAM KAND LAMOG[/b] and [b]Bill APPER SRIM [/b](Goper)"right now i am doing this once is working and another one is saying issue with length character in substringrtrim (ltrim (SUBSTRING(MatterColumn,CHARINDEX('between',MatterColumn  COLLATE Latin1_General_CS_AI)+8, ( Charindex(' and ', MatterColumn  COLLATE Latin1_General_CS_AI,CHARINDEX('between',MatterColumn  COLLATE Latin1_General_CS_AI)+8) - CHARINDEX('between',MatterColumn  COLLATE Latin1_General_CS_AI)-8 )  ) )) Part1,rtrim (ltrim (SUBSTRING(MatterColumn,CHARINDEX(' and ',MatterColumn  COLLATE Latin1_General_CS_AI)+5, ( Charindex(' (', MatterColumn  COLLATE Latin1_General_CS_AI,CHARINDEX(' and ',MatterColumn  COLLATE Latin1_General_CS_AI)+8) - CHARINDEX(' and ',MatterColumn  COLLATE Latin1_General_CS_AI)-5 )  ) )) Part2please help methanks in advanceasitti</description><pubDate>Fri, 16 Nov 2012 18:53:39 GMT</pubDate><dc:creator>asita</dc:creator></item></channel></rss>