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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".