I have small question about SQL Server, please tell me how to solve this issue
Table: emp
id name
---------------
1 abc_ra
You miss the case where there's no underscore in the string, which causes the error. Instead, try:
select
case CHARINDEX('_', name) when 0 then name
else SUBSTRING(name, 1, CHARINDEX('_', name) - 1) end firstName,
case CHARINDEX('_', name) when 0 then name
else SUBSTRING(name, CHARINDEX('_', name) + 1, LEN(name)) end lastname
from emp
I assume in the case of a single word, you want to show them as both the first name and last name. You can change that value to whatever you prefer.