tags:

views:

29

answers:

1

I have a column that contains page titles, which has the website name appended to the end of each. (e.g. Product Name | Company Name Inc.) I would like to remove the " | Company Name Inc." from multiple rows simultaneously. What SQl query commands (or query itself) would allow me to accomplish this?

To re-illustrate, I want to convert multiple rows of 1 column from this: Product Name | Company Name Inc.

To this: Product Name

+1  A: 

You mean something like (in SQL Server):

Update Table
Set PageTitle = Substring( PageTitle, 1, CharIndex( '|', PageTitle ) - 1)

Basically, I'm using CharIndex to find the delimiter ('|') and then using Substring to find everything just before the delimiter.

In MySql I believe it would be along the lines of:

Update Table
Set PageTitle = Substring( PageTitle, 1, Substring_Index(PageTitle, '|' ) - 1)
Thomas
I feel silly, I just remembered about the replace function, here's what I did.SET PageTitle = replace(Page Title, ' | Company Name Inc.', '');
Scott
@Scott - Ah. I assumed that "| Company Name Inc." was a placeholder for names as opposed to the literal static text.
Thomas