COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: cabaynes on 30 Sep 2011 01:28:50 PM

Title: Remove all spaces within a string? *Banging my head against the wall*
Post by: cabaynes on 30 Sep 2011 01:28:50 PM
I have a string value that has a few thousand records, and many of them are multi-word items, so they contain spaces. I need to get rid of all of the spaces.

I am aware of the TRIM function, but that is only good for leading and trailing spaces, not ones in the middle of the string.

The REPLACE function does not seem to be working for me, nor does SUBSTITUTE, or COLLAPSE. I attempted to cast the string to a varchar, then use REPLACE, but that does not seem to work either.

I've been scouring the internet for hours trying to figure this out. Any ideas would be greatly appreciated!

Thank you
Charles
Title: Re: Remove all spaces within a string? *Banging my head against the wall*
Post by: Lynn on 30 Sep 2011 03:36:43 PM
What do you mean when you say "does not seem to work"? Error? Unexpected result?

Also, what database are you using?

The REPLACE function works fine for me

REPLACE([MyField],' ', '')

There is also a TRANSLATE function, but that doesn't allow me to specify an empty string. I am on DB2.

Of course the ideal solution is to do this on the database side.
Title: Re: Remove all spaces within a string? *Banging my head against the wall*
Post by: cabaynes on 30 Sep 2011 04:46:26 PM
Yes, I get an error. We are using Teradata database, so I don't think the REPLACE function is available in anything other than Oracle.
Title: Re: Remove all spaces within a string? *Banging my head against the wall*
Post by: CognosPaul on 02 Oct 2011 06:39:28 AM
How much control do you have over the database? If none, is the DBA open to installing some UDFs?

If you can, download and import the following UDFs:
http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions (http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions)

I haven't worked with UDFs in a long time, and you may need to import them into the FM before you can use them.
Title: Re: Remove all spaces within a string? *Banging my head against the wall*
Post by: blom0344 on 02 Oct 2011 02:51:14 PM
Quote from: PaulM on 02 Oct 2011 06:39:28 AM

I haven't worked with UDFs in a long time, and you may need to import them into the FM before you can use them.

Yes, importing them into the FM model is required, but you also need to make sure that execution rights are established. At least on SQL server having read rights on the database is not enough when you start using UDF's. Pretty sure this goes for other RDBMS
Title: Re: Remove all spaces within a string? *Banging my head against the wall*
Post by: cabaynes on 03 Oct 2011 11:32:03 AM
Quote from: PaulM on 02 Oct 2011 06:39:28 AM
How much control do you have over the database? If none, is the DBA open to installing some UDFs?

If you can, download and import the following UDFs:
http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions (http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions)

I haven't worked with UDFs in a long time, and you may need to import them into the FM before you can use them.

Thanks for help. I have zero control over the database, but will speak to my DBA to see if we can get these features. Seems like "oreplace" is exactly what I'm looking for.

Regards!