Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL Replace Function Problems

MindBender77's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: Pittsburgh,Pa USA
Posts: 232
#1: Sep 12 '07
I have DB2 V7 for IBM. I have a simple select statement which produces 2 columns. Column 2 is smallint. I need col2 to say Picking instead of 720 or Verify instead of 740. Both 720 and 740 can be in the same result set. This is what I have so far. Any help will be greatly appreciated.

Select col1, varchar(replace('720', '720', 'Picking'), 10) from table1

Newbie
 
Join Date: Nov 2007
Location: Laren, Netherlands
Posts: 6
#2: Nov 2 '07

re: SQL Replace Function Problems


Try using a 'CASE' expression.

In your example it would go something like:

SELECT
col1,
CASE col2
WHEN <value1> THEN '<description1>'
WHEN <value2> THEN '<description2>'
...
END
FROM ...

You can do a lot more with CASE, but this should answer your question.
Reply