Home Forums SQL Server 7,2000 T-SQL Splitting a string from a column into three values RE: Splitting a string from a column into three values

  • great jo providing the setup data!

    Here's another fast way using the PARSENAME function;

    PARSENAME is usually used to split object names, like ServerName.Databasename.dbo.TableName,

    but can be used for IP address and other strings, and is limited to 4 parts.

    it also thinks the strings are right to left(4,3,2,1), where we would see the string as left to right (1,2,3,4)

    note that this assumes your data will not have periods in it,

    and is all three parts like your example data.

    select

    PARSENAME(REPLACE(SplitValue,'-','.'),3) AS PartT1,

    PARSENAME(REPLACE(SplitValue,'-','.'),2) AS PartT2,

    PARSENAME(REPLACE(SplitValue,'-','.'),1) AS PartT3,

    MytestTable.*

    FROM MytestTable

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!