I am using SQL Server 2005. I have a string with a special character : like:
XYZ:xyz@mail.com
I want to divide this string into two sub-strings and select into variables. The special character : is just a separator.
@variable1=XYZ
@variable2=xyz@mail.com
Please guide me on how it is possible.
String Dividing Guide:
Use
CHARINDEXto find the position of:.Use
SUBSTRINGto grab all the characters before the position of:, and put them into@variable1.Use
SUBSTRINGto grab all the characters after the position of:, and store them into@variable2.A possible implementation:
Output: