tags:

views:

591

answers:

2

Hello! :-)

In one of my resultsets i have column with char - data. I want to create another column, which carries altered data from the first column. There i want to exchange all 'ö' with oe.

I tried it like this:

Select NAME1,
    case when POSSTR(NAME1, 'ö') is not null then REPLACE(NAME1, 'ö', 'oe')
    end As __NAME1
from xyz;

and it failed. I don't get an error, but the ö is not replaced.

Am i making a mistake or is it simply not possible to perform this operation?

Thanks! Patrick

+1  A: 

According to the DB2 documentation, POSSTR returns 0 (not NULL) if the string is not found.

Tom H.
It works when state the query like this: Select cu.NAME1, case WHEN (POSSTR(lower(cu.NAME1), 'ö') <> 0) THEN '-------' ELSE '-' end As CusName1, With the query below i get no error but the ö isn't changed also. I guess something is wrong with my usage of the replace function? WHEN (POSSTR(lower(cu.NAME1), 'ö') <> 0) THEN REPLACE(lower(cu.NAME1), 'ö', 'oe')
Is it possible format the comments somehow better?
+1  A: 

You you want your second column to list all the rows, both changed and unchanged you can simply use:

Select 
    NAME1,
    REPLACE(NAME1, 'ö', 'oe') As __NAME1
from xyz;

also you can test this:

Select 
    NAME1,
    REPLACE(NAME1, 'ö', 'oe') As __NAME1
from 
    xyz
where
    POSSTR(NAME1, 'ö') <> 0
kristof