Link to home
Start Free TrialLog in
Avatar of jmvega00
jmvega00

asked on

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

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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.

Avatar of jmvega00
jmvega00

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks! My head was fry'd and this is going into a pretty complex update query. Thanks again :)