return 4 digit in SQL

Posted on 2009-04-28
Last Modified: 2012-05-06
How to get only the last four digit in MS-SQL 2005?
This is the account number is have, sample,  64564567
I need it to return only 4567.
Question by:VBdotnet2005
    LVL 12

    Expert Comment

    select 64564567 % 10000
    select fieldname % 10000
    LVL 10

    Accepted Solution

    SELECT RIGHT(YourFieldName,4) As YourFieldAlias FROM YOURTable
    LVL 11

    Assisted Solution

    by:N R
    select substring(yourfield,5,8)
    from table
    LVL 9

    Assisted Solution

    Try the RIGHT function.

    SELECT RIGHT(AccountNumber, 4) AS TruncatedAccountNumber FROM YourTable

    Open in new window


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now