Remove trailing characters of a field in a view

  • I'm creating a view that has a field called PO_number. The PO numbers are varying lengths. They have trailing three spaces followed by a number of varying length. For example '8769098 987'. I want to only see the first set of numbers '8769098'. What function would work best to accomplish this?

    Thanks

  • A combination of Left and Charindex.

    declare @String varchar(20);

    select @String = '123 456';

    select left(@String, charindex(' ', @String);

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • That works. Thanks

  • You're welcome.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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