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 |
ddobbertin
Yak Posting Veteran
51 Posts |
Posted - 2009-02-27 : 11:21:07
|
Trying to take a column of employee names that are listed "Firstname Lastname" and sort them by their Lastname. Usually I would split the name into an array outside of SQL. Is there a similar split function available in SQL? |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-27 : 12:03:07
|
There are split functions if you look for it in script library.For your case, you coul use this,select right('firstname lastname',len('firstname lastname')-charindex(' ','firstname lastname'))from yourtableorder by .. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-02-27 : 12:03:33
|
As far as I know, there is no split function available. But it can be achieved in SQL ...something like this..select * from urtable order by substring(name_col,charindex(' ',name_col)+1,len(name_col)) But you shouldn't be doing this in SQL..you are better off doing it outside SQL just the way you are doing now. |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2009-02-27 : 12:10:46
|
He's fine doing it in SQL.This function will do it for him:http://sqlblindman.pastebin.com/f68f37c15________________________________________________If it is not practically useful, then it is practically useless.________________________________________________ |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-02-27 : 12:12:14
|
Oh..I think I can use this function for some of my own needs as well...This is great.Thanks for the info blindman.. |
|
|
|
|
|