If Condition In Sql Function Substring