need to remove a pipe in a part number

  • I have a part with a pipe in it and a number, (e.g.12345|03).

    I need to remove the pipe and the number to the right of it, but the number varies in length.

    What is the function that will pull it out??  I need a substring, but one that looks for the | pipe.

    Thanks

     

    -k

  • You can use PATINDEX to find the location of the pipe and then use that in the substring function. 

  • DECLARE @tbl TABLE(PartNo varchar(20))

    INSERT INTO @tbl VALUES('12345|03')

    SELECT SUBSTRING(PartNo, 1, CHARINDEX('|', PartNo)-1)

    FROM @tbl

    WHERE  CHARINDEX('|', PartNo) > 0

  • or:

    DECLARE @tbl TABLE(PartNo varchar(20))

    INSERT INTO @tbl VALUES('12345|03')

    SELECT REPLACE(PartNo, '|','')

    FROM @tbl

    WHERE CHARINDEX('|', PartNo) > 0


    * Noel

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

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