[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4887
  • Last Modified:

Remove punctuation, spaces and capitalization using DB2 SQL Query

Hi to all,

I have a question. Can we remove punctuation, spaces and capitalization from the field using DB2 SQL query or not? Actually, I come to the point where I need to compare a field excluding all the punctuation, spaces and capitalization. In other words just including alpha-numeric characters. Is there any DB2 SQL function to return just alpha-numeric characters out of string field?

If there is any confusion or any further question, please feel free to ask me.

Thanks,
Sharad Bajracharya
0
sharadrb
Asked:
sharadrb
1 Solution
 
LowfatspreadCommented:
you may get a better response in the DB2/UDB topic area

what particular version and OS of DB2 are you using?

you can/should be able to achieve what you desire....

use
the REPLACE FUNCTION TO replace all the punctuation symbols that are present
(unfortuantley you have to specify each one)
and use UPPER to convert everything to the same (upper case (or LOWER) )

so



like

replace(
replace(
replace(
replace(
Replace(
Upper(STRIP(COLUMNNAME,B,' '))          -- remove leading and trailing spaces from the column and convert to upper case...  
,',','')                                                    -- convert commas to empty strings
,' ','')                                                    -- convert embedded spaces to empty strings
,'.','')                  -- fullstops
,'''','')                 -- single quotes
,'"','')                 -- double quotes may need to use '""',''  

and so one keep adding replace (.... ,string to replace, emmpty string) until all the puncutation is gone....

you may want to establish this is a view on the table...

alternativly you could put this into a stored procedure of function depending on the DB2/UDB version.


hth  
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now