Clicky

Dear fellow developers:

I have a column in my table called "CATEGORYINFO" that has info of the following form:

Goods: N  | Services: Y  | Construction: N

I need to create an UPDATE SQL statement that will read the data in this column, and pull whichever value has a "Y" next to it, and insert it into the "CATEGORY" column inside the same table.  These three values (Goods, Services, Construction) are consistent throughout, and only one of these values can have a "Y" next to it.  Can anyone explain to me how to do this?

Thanks in advance to all who reply.

asked 12/15/2011 04:29

fsyed's gravatar image

fsyed ♦♦


4 Answers:
Try this:

update table set category=regexp_replace(CATEGORYINFO,'(.*)(Goods|Services|Construction)(: Y)(.*)','\2');
link

answered

slightwv's gravatar image

slightwv

Thanks so much for your prompt reply.  I'm executing your SQL code from C#.  When I compile my code, I get the error message, "Unrecognized escape sequence", referring to:

...)(.*)','\2');

Can I correct this problem by adding another backslash (i.e. )(.*)','\\2'); )?  Just wondering.
link

answered 2011-12-15 at 12:42:43

fsyed's gravatar image

fsyed

>>Can I correct this problem by adding another backslash

That should work.
link

answered 2011-12-15 at 13:02:02

slightwv's gravatar image

slightwv

Thanks very much for your prompt reply.  Your solution worked!  Full points!

Take care.
link

answered 2011-12-15 at 13:04:23

fsyed's gravatar image

fsyed

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×51
×17
×132

Asked: 12/15/2011 04:29

Seen: 293 times

Last updated: 12/15/2011 05:06