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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Move first 4 characters to the end in a field?

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2013-07-02 : 17:57:15
Hello I have a table items and a column named itemname the I need to move the first 5 characters to the end, but not all the fields are the same length. Some look like this VOL.3-VARIOUS and some look like this VOL.5-VARIOUS-NAME. How can I get it to move the first 5 charaters to the end so they would all be the same like this VARIOUS-VOL.3 and VARIOUS-NAME-VOL.5. Do I use SUBSTRING(itemname, 1, 5) with other commands?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-07-02 : 19:49:08
UPDATE dbo.Table1 SET Col1 = SUBSTRING(Col1, 7, LEN(Col1)) + '-' + LEFT(Col1, 5) WHERE Col1 LIKE 'VOL.[0-9]-%';





N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -