Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 split string and return specific postion string

Author  Topic 

kirank
Yak Posting Veteran

58 Posts

Posted - 2013-11-20 : 01:41:14
SELECT
REPLACE(@ReqType ,'ALL', function call to split(string val, position) ) as [Request Type],
From
Temptable

Here i would create to call the function lets say SplitString with (string , position)
and return specific position string from that split result

ex:
1. dbo.splitfunction(Menu3_RI_ANCE_2013.docx,2) this will returns RI
2. dbo.splitfunction(Menu3_RI_ANCE_2013.docx,3) this will returns ANCE
like that..

Thanks for the help.



---------------------------

http://codingstuffsbykiran.blogspot.com | http://webdevlopementhelp.blogspot.com

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-11-20 : 01:48:35
use fnParseString() from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-20 : 02:05:16
http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
http://visakhm.blogspot.in/2013/01/string-pattern-search-xml-based-method.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kirank
Yak Posting Veteran

58 Posts

Posted - 2013-11-20 : 02:33:26
quote:
Originally posted by khtan

use fnParseString() from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]





Thanks, i did that using fnGetCsvPart function.

---------------------------

http://codingstuffsbykiran.blogspot.com | http://webdevlopementhelp.blogspot.com
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2013-11-23 : 13:11:21
@kirank,

I'll recommend that if your string is 8k or less in length, then any splitter that contains any of the following is going to be comparatively slow to using a Tally CTE or Tally Table.

WHILE Loop
Recursive CTE
Concatenation of any type
XML (exception is if you're passing the function XML)

With that thought in mind, how long are the strings that you wish to split and get the element number for?

--Jeff Moden
RBAR is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row".

First step towards the paradigm shift of writing Set Based code:
"Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

When writing schedules, keep the following in mind:
"If you want it real bad, that's the way you'll likely get it."
Go to Top of Page
   

- Advertisement -