Getting Last 4 Digit of PAN Number in Sql Server

Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 775
Sometimes we require not to show PAN number to any user,and we have to show only 4 last digit,so in sql Server,we can use following ways.
Suppose,we have PAN Number as ABCDE1234F,and we want to get last 4 digit as 234F.

1st Way Using Reverse method with Substring method:-
Select Reverse(Substring (Reverse('ABCDE1234F'),1,4)) As LastFourLetters;

2nd Way Using Only Substring method:-
Select Substring ('ABCDE1234F',7,4) As LastFourLetters;

3rd Way Using Right method:-
Select Right('ABCDE1234F',4) As LastFourLetters;

Note:-You can also query with column as
Select Right(Pan_Number,4) As LastFourLetters From Employee_Master;

Comments or Responses

Login to post response