473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Moving text in a string within a row

I have list of titles in a database, many of which begin with "the..."

Is there an sql statement to move the "the" from the beginning of the column
and place it at the end

eg "The Big Blue House" would become "Big Blue House, The"

"The Cat and Dog" would become "Cat and Dog, The"

Many Thanks

Craig
Jul 20 '05 #1
5 1250
Craig Keightley wrote:
eg "The Big Blue House" would become "Big Blue House, The"
"The Cat and Dog" would become "Cat and Dog, The"


SELECT IF(POSITION("the" IN title) > 0,
CONCAT(SUBSTRING(title FROM 5), ", The"),
title) AS title_alphabetizable
FROM . . .

I tried this with a quick table in my test database, and it seems to
work. POSITION() is even case-insensitive.

Regards,
Bill K.
Jul 20 '05 #2
Bill Karwin wrote:
SELECT IF(POSITION("the" IN title) > 0,


Oops! Perhaps that string should be "the " (with a space within the
quotes), so you don't get results like "lma and Louise, The".

Regards,
Bill K.
Jul 20 '05 #3
thanks i'll give it a go
craig

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ce********@enews1.newsguy.com...
Bill Karwin wrote:
SELECT IF(POSITION("the" IN title) > 0,


Oops! Perhaps that string should be "the " (with a space within the
quotes), so you don't get results like "lma and Louise, The".

Regards,
Bill K.

Jul 20 '05 #4
That works as a select statement but how do i update the records, it only
displays the results
"Craig Keightley" <do**@spam.me> wrote in message
news:41**********************@news-text.dial.pipex.com...
thanks i'll give it a go
craig

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ce********@enews1.newsguy.com...
Bill Karwin wrote:
SELECT IF(POSITION("the" IN title) > 0,


Oops! Perhaps that string should be "the " (with a space within the
quotes), so you don't get results like "lma and Louise, The".

Regards,
Bill K.


Jul 20 '05 #5
Fixed it
update tablename set fieldname = concat(substr(...), ', the') where
fieldname like 'the %'

"Craig Keightley" <do**@spam.me> wrote in message
news:41**********************@news-text.dial.pipex.com...
That works as a select statement but how do i update the records, it only
displays the results
"Craig Keightley" <do**@spam.me> wrote in message
news:41**********************@news-text.dial.pipex.com...
thanks i'll give it a go
craig

"Bill Karwin" <bi**@karwin.com> wrote in message
news:ce********@enews1.newsguy.com...
Bill Karwin wrote:
> SELECT IF(POSITION("the" IN title) > 0,

Oops! Perhaps that string should be "the " (with a space within the
quotes), so you don't get results like "lma and Louise, The".

Regards,
Bill K.



Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ryan Spencer | last post by:
Hello Again Everyone, As previously aforementioned in my post 'Moving around in a string', I've finally found my result to the pig_latin approach. import string choice =...
5
by: Craig Keightley | last post by:
I have list of titles in a database, many of which begin with "the..." Is there an sql statement to move the "the" from the beginning of the column and place it at the end eg "The Big Blue...
1
by: Kirok | last post by:
Hey Everyone, Thanks for reading, heres what I'm trying to do I have an array of say 10 items each item contains the text / description for a room. Now I would like to create a class (lets...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
2
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
1
by: mmalloc | last post by:
I have the following code to move some text with javascript that works both on ie and ff. I can't make it XHTML compatble. If i remove the doctype info it will work. I'm sorry to bother with such...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
3
by: Avi | last post by:
Hi all, I have a web page with Multiline TextBox. Every 3 seconds I refresh the page and display all received messages in this TextBox. When the TextBox is updated (The Text property is set). ...
5
by: adarshyam | last post by:
Hi friends, I have an interesting problem in vb.net. And I am struggling to get a solution for this..m trying for the past 3days.. It’s to calculate moving average for the inputs given by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.