Question: In my sql database I have a table like "REG\_DET", This table mainly include 3 data member. NAME,AGE,SSN. Here SSN is a string include more than 10 character. Here my problem is when i read SSN from the table i need only last 4 character that is

Eg. `Rohith , 25 , 1023456457`

result only include `Rohith , 25 ,6457`(last 4 character of SSN)

Is It possible to do it in a sql select query(at the time of selection). If anyone know pls help me

Answer: 
You can use `RIGHT` function:

```
SELECT NAME,
       AGE,
       RIGHT(SSN, 4) As SSN_Short
FROM REG_DET

```

(assuming that you're using [SQL-Server](http://msdn.microsoft.com/en-us/library/ms177532.aspx) or [MySQL](http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_right))

**Edit**: Since you're using `TEXT`, you need to conver it to `VARCHAR` first:

```
SELECT NAME,
       AGE,
       RIGHT(CONVERT(VARCHAR(8000),SSN)), 4) As SSN_Short
FROM REG_DET

```
To get the last 4 digits from the `SSN` column , you can also use `SUBSTRING`. If the length of the SSN column is 10, then you can use the following query:

```
 SELECT NAME, AGE, SUBSTRING(SSN, 6, 4) FROM REG_DET

```