Possible Duplicate:
Split Function equivalent in tsql?
I have @FirstLastName = 'First Last'.
I need to split string in two variables @FirstName and @LastName.
In @FirstName goes 'First'.
In @LastName goes 'Last'.
Possible Duplicate:
Split Function equivalent in tsql?
I have @FirstLastName = 'First Last'.
I need to split string in two variables @FirstName and @LastName.
In @FirstName goes 'First'.
In @LastName goes 'Last'.
This should do the trick but it's only a quick hack (SQL Fiddle):
SET @FirstName = substring(@FirstLastName
, 1
, charindex(' ', @FirstLastName)-1)
SET @LastName = substring(@FirstLastName
, charindex(' ', @FirstLastName)
, 999)
-- if you want to calculate the actual @LastName length,
-- replace 999 with len(@FirstLastName)-charindex(' ', @FirstLastName)+1
For a more elegant and robust way see Split function equivalent in T-SQL?.