Find candidate having experience greater than 2 from string value in SQL Server

Last Reply 4 months ago By dharmendr

Posted 4 months ago

in my sql database experience is saved as 1 Yr 9 Months , in sql query i want to find candidates which has experience greater that 2 or anything else, how to solve this in sql query

Posted 4 months ago

Hi mukesh1,

Check below Query.

Note: You need to save the record in Year and Months format in DataBase as like below.

It is better if you can save in Numeric Format instead of String.

SQL

DECLARE @Test AS TABLE (Experience VARCHAR(50))
INSERT INTO @Test VALUES('1 Yr 9 Months')
INSERT INTO @Test VALUES('2 Yr 1 Months')
INSERT INTO @Test VALUES('5 Yr')

SELECT * FROM @Test WHERE SUBSTRING(Experience,1,2) > 1

Output

Experience

2 Yr 1 Months

5 Yr