I completely agree with manchanx in Solution 1, but to answer the question as asked ...
You can use a CASE clause - see
A Simple Use of SQL CASE Expression[
^]. For example:
select case when CHARINDEX(' ', table_a.fullname) = 0 then table_a.fullname ELSE
left(table_a.fullname, charindex(' ', table_a.fullname) - 1) END as [Last Name]
FROM table_a
INNER JOIN table_b ON table_a.id = table_b.id
WHERE table_b.region = 'C'
You may also need to consider a situation where fullname consists of forename+middlename+surname - in which case you will need to find the last space not the first one. A neat trick to use is the
REVERSE[
^] function.
select case when CHARINDEX(' ', table_a.fullname) = 0 then table_a.fullnameName ELSE
REVERSE(SUBSTRING(REVERSE(table_a.fullname),1, CHARINDEX(' ', REVERSE(table_a.fullname)))) END as [Last Name]
FROM table_a
INNER JOIN table_b ON table_a.id = table_b.id
WHERE table_b.region = 'C'
As you can see it's starting to get a bit messy - so I refer you to Solution 1