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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 want instr to toggle firstname and lastname

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2014-10-08 : 14:29:27
I have first name space and last name space(emp2)

the emp2 is fixed for all rows has last part emp2 in brackets.

want to present toggling just the firstname lastname part.

for micheal jackson (emp2)

it shouod be jackson michael (emp2)

select emp_fullname from Table_employee;

Thanks a lot for the helpful info.,

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-08 : 14:40:52
I can't understand your post. You just want lastname first? Do you have separate columns for the data or just the fullname column?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-10-08 : 14:41:23
Here is an eample using the PARSENAME function.
DECLARE @x VARCHAR(255) = 'micheal jackson (emp2)';

SELECT PARSENAME(REPLACE(@x,' ','.'),2) + ' '+ PARSENAME(REPLACE(@x,' ','.'),3)
+ ' ' + PARSENAME(REPLACE(@x,' ','.'),1)

Ideally, I wouldn't do it this way. I would find a string splitter function such as the one here http://www.sqlservercentral.com/articles/Tally+Table/72993/ and use that function like this:
DECLARE @x VARCHAR(255) = 'micheal jackson (emp2)';

SELECT LTRIM((
SELECT ' ' + Item FROM dbo.DelimitedSplit8K(@x,' ') ORDER BY
CASE ItemNumber
WHEN 2 THEN 1
WHEN 1 THEN 2
WHEN 3 THEN 3
END FOR XML PATH('')))
The dbo.DelimitedSplit8K is in Figure 21 of that article.
Go to Top of Page
   

- Advertisement -