• Teee (8/15/2012)


    Hi,

    I need to take the characters from the left before the '/' string and insert into a column and the characters on the right after the '/' string into another column.

    This is how my sample data looks, its not all the same in the table :

    /*--[Room / Shelf]

    Flammables/solvents

    TC fridge/freezer

    U2-16/Freezer

    U2-16/Fridge

    U2-16/Poisons cabinet

    */

    Select LEFT([Room / Shelf], 5)

    From ChemInventory

    Where [Room / Shelf] LIKE '%/%'

    I don't want to count the characters as I have different records in my table, how can I achieve this without using the syntax above?

    Thanks

    Teee

    Leaving aside the fact that a column called 'Room / Shelf' is just plain nasty :-), you need something like this:

    select [Room / Shelf]

    ,left([Room / Shelf], charindex('/', [Room / Shelf]) - 1)

    ,right([Room / Shelf], len([Room / Shelf]) - charindex('/', [Room / Shelf]))

    From ChemInventory

    Where [Room / Shelf] LIKE '%/%'

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.