Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Query for stripping first 5 characters

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
isaacr25
Asked:
isaacr25
  • 3
1 Solution
 
chapmandewCommented:
select last4 = right(ssn, 4)
from table1
0
 
isaacr25Author Commented:
This is a select query. Will this actually remove the preceding characters, leaving 4 characters?
0
 
chapmandewCommented:
whoops...didn't realize that you wanted to actually update the values...

update t1
set ssnfield = right(ssnfield, 4)
from table1
0
 
jamesguCommented:
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
 
chapmandewCommented:
yep, good catch...forgot my alias.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now