Tuesday 9 June 2015

MSSQL - How to get First name and last name from string or how to read until first empty space and after first empty space


Watch this example on YouTube:
Here is my table:

 
 The following statement
select CustomerName,
  Substring(CustomerName, 1, (CHARINDEX(' ', CustomerName + ' ')-1)) as FirstName,
  Substring(CustomerName, LEN(Substring(CustomerName, 1, (CHARINDEX(' ', CustomerName + ' ')+1))), LEN(CustomerName)) as LastName

from Table3

will produce this result:










1 comment:

  1. In My SQL LogDate Give me both time and date but I want to divide LogDate in to two column first is date and second one is Time

    ReplyDelete