Need to strip data in a column using a Trigger- Please help!

  • DBA's or Developers ,

    I'm trying to strip data from a column in a table using an UPDATE trigger.  I've already created the initial logic to populate the data into column2 from column1.  But I want to remove the full name (e.g. John Doe) and the parentheses (e.g. Data123).       

    EXAMPLE OF HOW IT LOOKS NOW:

    Column1                                                   Column2           

    John Doe (Data123)                                    John Doe (Data123)

    EXAMPLE OF HOW I WANT IT TO LOOK:

    Column1                                                   Column2           

    John Doe (Data123)                                    Data123

    Thanks!

  • Hi,

    Try this

    select column1, substring(columnn1,charindex(columnn1,'(')+1,charindex(columnn1,')') as Column2

    from tbl

     

     


    Helen
    --------------------------------
    Are you a born again. He is Jehova Jirah unto me

  • Helen,

    Thank you!   I used something similar to what you wrote and it worked.

    DECLARE @In nvarchar(250)

    SET @In = 'Baxter Lane (BLANE)'

    SELECT SUBSTRING(@In, CHARINDEX('(', @In) + 1, CHARINDEX(')', @In) - CHARINDEX('(', @In) - 1)

    David  

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

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