| id | word | length |
select top 1
id, word, length
from words
order by abs(length - 5) asceding
SELECT TOP 1 T.*
FROM (
SELECT T.word,
T.length
FROM (
SELECT TOP 1 *
FROM Table T
WHERE T.length >= 5
ORDER BY T.length
) T
UNION ALL
SELECT T.word,
T.length
FROM (
SELECT TOP 1 *
FROM Table T
WHERE T.length <= 5
ORDER BY T.length DESC
) T
) T
ORDER BY T.length