Solved

Query for stripping first 5 characters

Posted on 2008-10-31
5
191 Views
Last Modified: 2012-05-05
I need to run a query on a database table (let's call it TABLE1) to KEEP the LAST 4 characters for all values in the SSN field. How do I do this? Thanks.

Database: SQL Server 2000
0
Comment
Question by:isaacr25
  • 3
5 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22850733
select last4 = right(ssn, 4)
from table1
0
 

Author Comment

by:isaacr25
ID: 22850748
This is a select query. Will this actually remove the preceding characters, leaving 4 characters?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 22850804
whoops...didn't realize that you wanted to actually update the values...

update t1
set ssnfield = right(ssnfield, 4)
from table1
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22850923
a typo from chapmandew's post

update t1
set ssnfield = right(ssnfield, 4)
from table1 t1

or

update table1
set ssnfield = right(ssnfield, 4)
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22850935
yep, good catch...forgot my alias.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

23 Experts available now in Live!

Get 1:1 Help Now