Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Constraint Violating Yak Guru

274 Posts

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

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

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

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

Flowing Fount of Yak Knowledge

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  
 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.02 seconds. Powered By: Snitz Forums 2000