Home Forums SQL Server 7,2000 T-SQL Need to seperate string in two columns using T-SQL RE: Need to seperate string in two columns using T-SQL

  • create table testtable (Col1 varchar(50), Col2 varchar(50), Col3 varchar(50))

    go

    insert into testtable (Col1)

    SELECT 'Americas - NorthEast'

    UNION

    SELECT 'Americsa - SouthEast'

    UNION

    SELECT 'Europe - North Region'

    UNION

    SELECT 'Asia - SouthEast'

    GO

    SELECT * FROM TESTTABLE

    update testtable

       SET COL2 = LEFT(COL1,PATINDEX('% %', COL1)),

           COL3 = RIGHT(COL1,LEN(COL1)-(PATINDEX('%-%', COL1)+1))

    GO

    SELECT * FROM TESTTABLE

    Hope this helps

    Wayne