Home Forums SQL Server 2008 T-SQL (SS2K8) How to retrieve two sets of values from one column RE: How to retrieve two sets of values from one column

  • -- one more test data row

    INSERT INTO MyTestTable (ID, Col1) SELECT 4, 'a longer string value1 / a much much much much longer string value2 / whatever / whatever / whatever'

    SELECT

    Col1,

    LEFT(Col1, position_of_first_slash - 1) AS Value1,

    SUBSTRING(Col1, position_of_first_slash + 1, CHARINDEX('/', Col1, position_of_first_slash + 1) - position_of_first_slash - 1) AS Value2

    FROM dbo.MyTestTable

    CROSS APPLY (

    SELECT CHARINDEX('/', Col1) AS position_of_first_slash

    ) AS ca1

    WHERE

    Col1 LIKE '%/%/%'

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.