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
 Update help!

Author  Topic 

parkse
Starting Member

3 Posts

Posted - 2011-12-30 : 13:28:06
Hi all! I'm new to SQL so I apologize in advance if I'm not using the correct terminology or jargon...

I was wondering if there's any way to update just a part of a string in a particular column. For example, if I have multiple "ivory [furniture]", is there any way I can set up a statement that replaces anything that has "ivory" in it to a different color like red?

Like...if word contains ivory, then replace with red.

Thanks in advance.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-12-30 : 13:39:55
Sure, you can do that. For example:

update YourTable set yourCol = replace(yourCol,'ivory','red');
Have a look at this page: http://msdn.microsoft.com/en-us/library/ms186862.aspx
Go to Top of Page

parkse
Starting Member

3 Posts

Posted - 2011-12-30 : 15:46:45
I tried to execute the statement but received an error message saying that "hi" was an invalid identifier.

UPDATE hcs.textline
SET textline = REPLACE(textline, 'hello', 'hi');

Any insight would be appreciated.

[EDIT] do I need to use asp as I imagine this is a TEXT type...? If so, I believe the replace function doesn't work...
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-12-30 : 17:01:08
Are you using Microsoft SQL Server? The statement that I had posted (and you tried) would work on SQL Server. Don't know about other DBMS's

Also:
Is your name of your table textline?
Is it in schema hcs?

You can test both of the above by executing this test query:
select top 10 * from hcs.textline
If the query runs correctly, is there a column with the heading textline in there?

If all of that is true, and you still receive an error message, can you post the exact text of the error message?

Note: Didn't get what you meant by "use asp". You can run the queries from SQL Server Management Studio in a query window.
Go to Top of Page

parkse
Starting Member

3 Posts

Posted - 2011-12-30 : 17:29:31
It's not Microsoft SQL but Med-SQL so that may be why the statement doesn't work...

I tried to execute the test query with no avail. The name of the table is hcs.textline and the column I'm trying to execute to replace fxn is called textline.
Go to Top of Page
   

- Advertisement -