Substring only if string length > 2
sql, substring
Solution
You could use `CASE`
Select ABRESC =
CASE WHEN LEN(ABRESC) > 2
THEN SUBSTRING(ABRESC, 1, 2) + '-' + SUBSTRING(ABRESC, 3, 5)
ELSE ABRESC END
From TABLE
Problem
I was wondering if it was possible to only substring if the string length is > 2? Here is my sample statement: `Select SUBSTRING(ABRESC, 1, 2) + '-' + SUBSTRING(ABRESC, 3, 5) AS ABRESC From TABLE` However, some fields are only 2 chars long so i was wondering if its possible to only substring when its longer than 2 chars?