Split string by space
This should work:
DECLARE @table TABLE (string VARCHAR(20))
INSERT @table VALUES ('ABC DEF')
INSERT @table VALUES ('XYZ')
INSERT @table VALUES ('EGF HIJ')
SELECT * FROM @table
WHERE CHARINDEX(' ', string) = 0
To get only 'XYZ' in the with a column containing
tableName.fieldName
'ABC DEF'
'XYZ'
'EGF HIJ'
Do this
SELECT *
FROM tableName
WHERE CHARINDEX(' ',fieldname) = 0
This is also work
select SUBSTRING(EmpName,0,CHARINDEX(' ',EmpName)),SUBSTRING(EmpName,CHARINDEX(' ',EmpName),LEN(EMPNAME))
from tblemployee