truncate string

  • How do you truncate a string everything before/after a certain character, including the character? The number of characters on either the right or left side of the character varies.

    shfdiuf/lsdfsjfij truncate everything to the right or left of the / character

    return:

    shfdiuf truncate everything to the right

    lsdfsjfij truncate everything to the left

    shfdiuf%lsdfsjfij truncate everything to the right or left of the % character

    return:

    shfdiuf truncate everything to the right

    lsdfsjfij truncate everything to the left

  • DECLARE @String VARCHAR(32) = N'shfdiuf/lsdfsjfij'

    SELECTLEFT(@String, CHARINDEX(N'/', @String) - 1),

    RIGHT(@String, CHARINDEX(N'/', @String) + 1)

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

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