Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Query for stripping first 5 characters

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

828 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