SQL Interview Questions | Verify the Table
Question
The following table consists of some data in the 7 rows
10/12 |
1a/90 |
23/11 |
2442 |
22/3c |
11/43 |
dd/ss |
You can clearly see that the table is not uniform. In reality, this table should consist the data in the form of NN/NN.
Verify that the first and last two characters are represented by numerical values and are separated by ‘/’ in the middle.
Print the message ‘NUMBER’ if valid, ‘NOT NUM’ if not.
in progress
1
SQL
55 years
1 Answer
1337 views
Great Grand Master 0
Answer ( 1 )
SELECT Column,
CASE WHEN ISNUMERIC(SUBSTRING(Column,1,2)) = 1 AND ISNUMERIC(SUBSTRING(Column,LEN(Column)-2,2)) = 1 AND
LEN(Column)=5 AND CHARINDEX(“/”,Column)=3 THEN “NUMBER”
ELSE “NOT NUM” END AS IS_NUM
FROM Table
for the second isnumeric shouldn’t it be len(column)-1
SUBSTRING(Column,1,2)) = 1