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 |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2012-12-09 : 05:22:33
|
hiI have these rows data in a field that looks like thisColAdemohello, hijohn doe, deardo you want to go, whereAnd i would like to shift whatever text after the comma to the front likehi demohellodear john doewhere do you want to goHow should go about it? Thanks a lot |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-09 : 08:22:12
|
[code]STUFF(ColA,1,CHARINDEX(',',ColA),'') + ' ' + LEFT(ColA,CHARINDEX(',',ColA)-1)[/code] |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-12-09 : 10:35:41
|
[code]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))),',',''))[/code] |
|
|
|
|
|
|
|