Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last 4 digits of ssn

Can someone, please, please help me here; I am very, very confused.

I am grabbing ssn values from an oracle database with this query:

SELECT
substr(SSN,6)
FROM MYTABLE

and I am getting the correct value of the last 4 digits

When I insert that value into a a sql server table, I am getting a different value.

For instance, let's assume that the ssn that I am grabbing is 123456789, in Oracle, I get 6789 which is correct.

However, after inserting the value into a sql server table as Insert into mytable (ssn) values(ssn), the value shows as 5678.

I also tried selecting the entire ssn as

SELECT
substr(SSN)
FROM MYTABLE

and then try inserting into a sql server db as:

Insert into mytable (ssn) values(right(ssn,4).

I still end up with 5678.

Can anyone, please tell me what I am doing wrong?

Thanks a lot in advance

like image 601
Kenny Avatar asked Dec 16 '22 09:12

Kenny


1 Answers

This is the right thing...

SELECT RIGHT('123456789',4)

Or you can check length of the field that you're using

like image 79
gngolakia Avatar answered Jan 22 '23 18:01

gngolakia