Solved

Query for stripping first 5 characters

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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…

757 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

25 Experts available now in Live!

Get 1:1 Help Now