How to SUBSTRING a Nbr field

  • I have a NBR field with 11 digits.  I need to convert it to CHAR and then SUBSTRING the last 2 characters in a select statement.  I've tried various combinations of CONVERT(CHAR,11),fieldname) and SUBSTRING(fieldname,9,2) and can't seem to get them nested together properly to display the last 2 positions.

    I think this is the right combination, based on the Transact help documentation, but can't make it fly.

    Any help will be appreciated.

     

    TIA,

    Joe

  • declare @number bigint

    set @number = 12345678911

    select right(convert(char(11),@number),2)

  • select Nbr%100

     

    _____________
    Code for TallyGenerator

  • Ray's suggestion should work for you. But using CONVERT and SUBSTRING, you would do this:

    SELECT

    SUBSTRING((CONVERT(CHAR(11),Fieldname)),9,2)

    FROM tablename

    The (CONVERT(CHAR(11), FieldName)) replaces the value that you want to 'substring'.

    -SQLBill

  • Excuse me, could someone explain to me what data type is NBR? I suppose it is some number, but couldn't find anything more precise about it. Thanks!

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

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