Solved

Query for stripping first 5 characters

Posted on 2008-10-31
5
199 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

805 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