Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-08-27 : 11:32:21
|
| Anthony White writes "Hello,I am attempting to create a view of a table that has a name field. This particular field actually contains full names, such as First Name, Last Name, and Middle Initial.I would like to write a SELECT statement that will separate the name by the spaces, and display the name as three columns rather than one column in a view.While I could use an approach for a single name such as,SELECT LEFT(fieldname, 5) AS [Last Night], Right(fieldname, 1) As [Middle Initial] FROM Table.This approach would not work when parsing a field with names of different lengths. I would need to parse based upon spaces within the field.Would anyone be able to provide direction.Thank you." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-08-27 : 12:00:08
|
| select left(name,charindex(' ',name)) , left(right(name,len(name) - charindex(' ',name)),charindex(' ',right(name,len(name) - charindex(' ',name)))) , right(name,charindex(' ',reverse(name))-1)leave you to work out what happens if no initial or only one name.Could use functions in this.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|