Click here to Skip to main content
13,660,195 members
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 13 Apr 2013
Licenced CPOL

TSQL Split a String by Delimiter

Rate this:
Please Sign up or sign in to vote.
TSQL split a string by delimiter


Say we have a registration table which stores successful registration information. At that table, we have a column “Name” which stores value as a combination of first name & last name delimited by ‘ ‘ [space]. Later at some point, we need to extract the first name or last name from that column, what to do?


The solution is a simple technique that will take the given input string (or column in my scenario) and split against the given delimiter. The technique is to get the first index of delimiter and return the string up to first index and return the first half. For the second half, start from first index of delimiter and take till the end of input string and you will get the second half. Simple, isn't it !!

  • Split and get the first half, delimiter is ‘ ‘ [space]
  • Split and get the second half, delimiter is ‘ ‘ [space]

And let me remind you that this solution is only applicable if you have a string with a single delimiter and resultant split count is <=2. Though this is small and wont work for more then one delimiter, it's quite handy for a situation like I explained above.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shahriar Iqbal Chowdhury/Galib
Chief Technology Officer
Bangladesh Bangladesh
I am a Software Engineer and Microsoft .NET technology enthusiast. Professionally I worked on several business domains and on diverse platforms. I love to learn and share new .net technology and my experience I gather in my engineering career. You can find me from here

Personal Site
Personal Blog
FB MS enthusiasts group
About Me

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 13 Apr 2013
Article Copyright 2013 by Shahriar Iqbal Chowdhury/Galib
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid