SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 place end string to the front
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sg2255551
Constraint Violating Yak Guru

272 Posts

Posted - 12/09/2012 :  05:22:33  Show Profile  Reply with Quote
hi

I have these rows data in a field that looks like this

ColA
demohello, hi
john doe, dear
do you want to go, where

And i would like to shift whatever text after the comma to the front like

hi demohello
dear john doe
where do you want to go

How should go about it? Thanks a lot

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 12/09/2012 :  08:22:12  Show Profile  Reply with Quote
STUFF(ColA,1,CHARINDEX(',',ColA),'') + ' ' + LEFT(ColA,CHARINDEX(',',ColA)-1)
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/09/2012 :  10:35:41  Show Profile  Reply with Quote
Declare @S Varchar(20)
Set @S = 'john doe, dear'

Select ltrim(REPLACE(REVERSE(Left(REVERSE(@S),CharIndex(',',REVERSE(@S)))),',','') + ' ' + REPLACE(REVERSE(Substring(REVERSE(@S),CHARINDEX(',',REVERSE(@S)),len(@S))),',',''))

Edited by - sodeep on 12/09/2012 10:36:14
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000