locked
get the 4 digit from right string .. RRS feed

  • Question

  • User-646447061 posted

    i have data in database like this A0001 ..
    how can i get data only 4 digit from last .. like this 0001
    thank you =)

    Saturday, March 19, 2016 6:00 AM

Answers

  • User-286291038 posted

    Hi,

    How about, 

    SUBSTRING([your column name], 2, 4)

    assuming that your data format is always a character followed by 4 digits.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2016 6:35 AM
  • User1633621018 posted

    Hi,

    You below code:

    SELECT 'A0001' [Original], RIGHT('A0001',4) [Changed]
    
    --output
    
    Original	Changed
    A0001	         0001

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2016 6:38 AM
  • User1633621018 posted

    Do it like below:

    var s = "A0001";
                var y = s.Substring(s.Length - 4);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 21, 2016 9:04 AM

All replies

  • User-286291038 posted

    Hi,

    How about, 

    SUBSTRING([your column name], 2, 4)

    assuming that your data format is always a character followed by 4 digits.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2016 6:35 AM
  • User1633621018 posted

    Hi,

    You below code:

    SELECT 'A0001' [Original], RIGHT('A0001',4) [Changed]
    
    --output
    
    Original	Changed
    A0001	         0001

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 19, 2016 6:38 AM
  • User-646447061 posted

    how about datatable ?

    var a = dt.Rows[0]["id_anggota"] .. id_anggota = a0001, get data 4 digit from right ?

    var a = 0001 .. thanks

    Saturday, March 19, 2016 11:26 AM
  • User1633621018 posted

    Do it like below:

    var s = "A0001";
                var y = s.Substring(s.Length - 4);
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 21, 2016 9:04 AM