CharIndex Manipulation (SQL 2012). Select Case Statement to remove Part of String after one or two specific characters.

  • Far from elegant, but this may work

    SELECT RTRIM(CASE WHEN CHARINDEX(',',Address) < CHARINDEX('*',Address)

    THEN SUBSTRING(Address,0, CHARINDEX(',',Address))

    WHEN CHARINDEX(',',Address) > CHARINDEX('*',Address)

    THEN SUBSTRING(Address,0, CHARINDEX('*',Address))

    ELSE Address

    END)

Viewing post 1 (of 2 total)

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