I have a table in sqlite db called [tblbook] with a column [authors]. What I am trying to do in the sql is to split the author values to firstname and the lastname and sort it on lastname. I did find this great code: 

```
 SELECT substr(BookAuthor, 1, NULLIF(CHARINDEX(' ', BookAuthor) - 1, -1)) AS [FirstName],
   substr(BookAuthor, CHARINDEX(' ', BookAuthor) + 1, LEN(BookAuthor)) AS [LastName]
 FROM tblBook where _id=3

```

It works perfectly on MSSQL but sqlite doesn't have the charindex function hence it fails.

Could anyone please be kind and advise me what should be the best approach to achieve this.