How to remove a Suffix from SQL field

Posted on 2013-10-15
Medium Priority
Last Modified: 2013-10-24
Hello Experts, I'm working with a field such as a part number, the field contains a 3 character suffix which I need to remove at the time of exporting data with a select statement. So if field is 2087502 , 14669501, 1244502, 10382503 I need to trim the last 3 digits and create
2087 , 14669, 1244, 10382

Please advise on your suggestions, I do not want to use replace as it will require me updating the SP for each variations of the suffix values in the future.
Question by:EddieIT
  • 3
  • 2
LVL 20

Expert Comment

ID: 39575002
Try this:

SELECT LEFT(PartNumber, LEN(PartNumber) - 3) AS TrimmedValue
FROM myTable

Accepted Solution

EddieIT earned 0 total points
ID: 39575028
Thank you, worked.
LVL 20

Expert Comment

ID: 39575053
Glad that worked for you.
LVL 20

Expert Comment

ID: 39585204
The objection is obvious.

Author Closing Comment

ID: 39596603
Worked great

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

600 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