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
 General SQL Server Forums
 New to SQL Server Programming
 Substring Manipulation Question

Author  Topic 

jet_black
Starting Member

4 Posts

Posted - 2009-02-05 : 17:18:38
I am trying to take the end of a text string in a table and append it to the beginning of the same text string.

Example:

TEXT MORETEXT 123456

I want:

123456 TEXT MORETEXT

What functions/syntax should I be exploring here for this task?


Thanks for any assistance!

jet_black
Starting Member

4 Posts

Posted - 2009-02-05 : 17:36:03
I got it, here it is for reference:

SELECT RIGHT(COL1, 6) + ' ' + LEFT(COL1, ((len(COL1))-7))
FROM TABLE1

Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-05 : 17:40:34
Is data going to be consistent?
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-05 : 23:48:40
if ur data will be 'TEXT MORETEXT 12345632' like this ur query will not works fine
so u this
select right(col1,charindex(' ',reverse(col1),1)-1) +' '+LEFT(col1, len(col1)-charindex(' ',reverse(col1),1))
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-05 : 23:52:26
Try this

DEclare @var VARCHAR(32)
set @var = 'TEXT MORETEXT 123456'

select parsename(replace(@var,' ','.'),1)+' '+parsename(replace(@var,' ','.'),3)+' '+parsename(replace(@var,' ','.'),2)
Go to Top of Page
   

- Advertisement -