MID, CHARINDEX OR SUBSTRING??

  • Hi

    Simple one this, for people in the know. I simply don’t know the terminology of what I’m looking for here.

    I would like to split the file in table below by the ':' symbol.

    What is the syntax for getting everything LEFT and everything RIGHT of the ':' symbol into a seperate field.

    For rowkey 1 I would like to be able to see ARMPMAEWC in 1 field and ARMPM in another.

    Thanks

    SAMPLE DATA

    CREATE TABLE PS_TestForOnline

    (

    rowkey INT,

    CLINIC VARCHAR (25),

    )

    INSERT INTO PS_TestForOnline

    VALUES('1','ARMPMAEWC:ARMPM' );

    INSERT INTO PS_TestForOnline

    VALUES('2','ACPAED:AC');

    INSERT INTO PS_TestForOnline

    VALUES('3','RCELDC:RC');

    INSERT INTO PS_TestForOnline

    VALUES('4','LEEDMECCH:LEED');

    select * from PS_TestForOnline

  • Try this:-

    select substring(clinic,1,charindex(':',clinic)-1),

    substring(clinic,charindex(':',clinic)+1,LEN(clinic))

    from PS_TestForOnline

  • Many Thanks for that. Works a treat.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply