| Author |
Topic |
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 05:08:29
|
| Dear All, Allow me to use that, what I want to achieve is if I have a varchar field, call NAME. I want to manipulate the data under that field that I will get different result.. i.eNAME ==> NAME2ALEX ==> LAEXDoing this with c# or vb, pose no problem, how can do this using t-sql.Thanks allI sign for fame not for shame but all the same, I sign my name. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 05:11:17
|
| [code]SELECT NAME,SUBSTRING(NAME,2,1) + LEFT(NAME,1) + SUBSTRING(NAME,3,LEN(NAME)) AS NAME2FROM YourTable[/code] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 05:18:37
|
[code]DECLARE @Sample TABLE ( Name VARCHAR(200), Name2 VARCHAR(200) )INSERT @Sample ( Name )SELECT 'Alex' UNION ALLSELECT 'SQLTeam' UNION ALLSELECT 'Peso'SELECT s.Name, w.tFROM @Sample AS sCROSS APPLY ( SELECT SUBSTRING(s.Name, Number, 1) FROM master..spt_values AS v WHERE v.Type = 'P' AND v.Number BETWEEN 1 AND DATALENGTH(s.Name) ORDER BY NEWID() FOR XML PATH('') ) AS w(t)[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 05:21:17
|
| Thanks Bro,Can we tweak this to work for any length greater than four. I expect the NAME field length to be greater than 4 and <= 255.Thanks Bro, You gave an insight...I sign for fame not for shame but all the same, I sign my name. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-09-26 : 05:26:09
|
quote: Originally posted by abacusdotcom Thanks Bro,Can we tweak this to work for any length greater than four. I expect the NAME field length to be greater than 4 and <= 255.Thanks Bro, You gave an insight...I sign for fame not for shame but all the same, I sign my name.
Yes, u can do for the length mentioned above. |
 |
|
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 05:28:45
|
| Thanks Peso, you are wonderful...Thanks for the help bro...Is there another way we can manipulate data to give new series, am only trying seek for more alternatives, am ok with the first solution.. After sqlteam forumn, we also learn from others.. lolThanksI sign for fame not for shame but all the same, I sign my name. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 05:32:32
|
UPDATE Table1SET Name2 = REVERSE(Name) E 12°55'05.63"N 56°04'39.26" |
 |
|
|
abacusdotcom
Posting Yak Master
133 Posts |
Posted - 2008-09-26 : 05:40:00
|
| @Peso... hmmmmmmmmmmmmmmmmm!I sign for fame not for shame but all the same, I sign my name. |
 |
|
|
|