[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

How do i truncate a nvarchar value like a social (123-45-6789) into just the last four digits?

Basically I'm trying to do what the title says. I'm using mssql 2005. I also have a query but it returns duplicite values. Well not really dups since the PK is different but it does have the same name values. Any easy way to get rid of that too? I'll include the query i'm running for that...
select distinct tbl_1.PK_P, tbl_1.LN, tbl_1.FN, tbl_1.social from tbl_1
inner join archive_2 on tbl_1.LN = archive_2.Ln 
and tbl_1.FN = archive_2.Fn
and Vn is not null

Open in new window

0
jmvega00
Asked:
jmvega00
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please clarify with sample data what exactly you are trying to do...

>I also have a query but it returns duplicite values
there are most surely due to the join, with 1 to many relationship between the 2 tables.

0
 
jmvega00Author Commented:
ok.
assume: tbl_person with fields fname, lname, social
lets say it only contains data: john, doe, 123-45-6789
I want to truncate all the values in the social field so it only stores the last four digits so when I do a

select social from tbl_person
it only returns for example: 6789

what update or comand would i have to run to achieve this truncate?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
UPDATE tbl_person
  SET social = RIGHT(social, 4)
0
 
jmvega00Author Commented:
Thanks! My head was fry'd and this is going into a pretty complex update query. Thanks again :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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