[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

return 4 digit in SQL

Posted on 2009-04-28
4
Medium Priority
?
487 Views
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.
0
Comment
Question by:VBdotnet2005
4 Comments
 
LVL 12

Expert Comment

by:udaya kumar laligondla
ID: 24252699
use
select 64564567 % 10000
or
select fieldname % 10000
0
 
LVL 10

Accepted Solution

by:
ALaRiva earned 200 total points
ID: 24252710
SELECT RIGHT(YourFieldName,4) As YourFieldAlias FROM YOURTable
0
 
LVL 12

Assisted Solution

by:Nathan Riley
Nathan Riley earned 100 total points
ID: 24252711
select substring(yourfield,5,8)
from table
0
 
LVL 9

Assisted Solution

by:tillgeffken
tillgeffken earned 200 total points
ID: 24252715
Try the RIGHT function.

SELECT RIGHT(AccountNumber, 4) AS TruncatedAccountNumber FROM YourTable

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

834 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