SQL Server Performance Forum – Threads Archive
Parse this string….TEXT:9:GETTHISONLY:0 Ok, so we see the delimiters ‘:’, and I need to extract the value between the second ‘:’ and the last ‘:’, to return ‘GETTHISONLY’. It will need to be so I can use it on any length string, but the pattern will always be the same. Please provide way to do this via tsql…….TIA!
looks like homework question.
check out CHARINDEX function in books online. If you are still not able to get the query working post the query you have and we can guide you. ***********************
SQL Server MVP
SELECT PARSENAME(REPLACE(‘TEXT:9:GETTHISONLY:0’, ‘:’,’.’), 2)
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderatorhttp://www.sql-server-performance.com
WOW, Frank! That’s incredibly simple! – And it works for 2000 too!<br /><br />I see the PARSENAME function only parse where the delimiter is ‘.’, so I totally understand.<br /><br />Genius! You can’t believe the substrings and multi-line functions I came up with <img src=’/community/emoticons/emotion-4.gif’ alt=’‘ /><br /><br />Thanks, again!
Glad it works for you. Usually this string search and compare questions turn out much more complicated than initially thought.[<img src=’/community/emoticons/emotion-1.gif’ alt=’‘ />]<br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br />Contributing Editor, Writer & Forum Moderator<a target="_blank" href=http://www.sql-server-performance.com>http://www.sql-server-performance.com</a><br />Webmaster:<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a>
Note that if the string has more than four : , then you need to modify the code accordingly
Also, if you want to show the data in front end, it is very easy to use Split function there Madhivanan Failing to plan is Planning to fail