To remove the space in the string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
lakshmipriya
Participant
Posts: 31
Joined: Tue Jul 13, 2004 5:26 am
Location: chennai
Contact:

To remove the space in the string

Post by lakshmipriya »

How can i achieve the output of the string with its space in between being removed in DB2 stage written in DB2 as a query

ex. input col: AB IT

req output col:ABIT
Lakshmi
richdhan
Premium Member
Premium Member
Posts: 364
Joined: Thu Feb 12, 2004 12:24 am

Post by richdhan »

Hi Lakshmi,

Check Trim(input col, " ", "A") works.

--Rich
anupam
Participant
Posts: 172
Joined: Fri Apr 04, 2003 10:51 pm
Location: India

Post by anupam »

To add
Trim(input col, " ", "A")
First argument is the input data
2nd argument is the character which is space in your case.
3rd argument is the option which is "A" which means ALL
----------------
Rgds,
Anupam
----------------
The future is not something we enter. The future is something we create.
lakshmipriya
Participant
Posts: 31
Joined: Tue Jul 13, 2004 5:26 am
Location: chennai
Contact:

Post by lakshmipriya »

i want to make this trim inside the DB2 query in a DB2 API stage itself could u pls let u know more exact query for writing the same
Lakshmi
anupam
Participant
Posts: 172
Joined: Fri Apr 04, 2003 10:51 pm
Location: India

Post by anupam »

I have not worked on DB2 but i think if you use tim(inputCol) function, it will remove all the spaces.

Try using it, it should work.
----------------
Rgds,
Anupam
----------------
The future is not something we enter. The future is something we create.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Check out the DB2 help on TRIM - it may only remove "extraneous" spaces (leaving a single space).
In this case, and if the pieces either side of the space are of known size, you could use substring and concatenation techniques.

Code: Select all

SELECT SUBSTRING(Product FROM 1 FOR 2) || SUBSTRING(Product FROM 4 FOR 2) FROM tablename;
or

Code: Select all

SELECT CONCAT(SUBSTR(Product,1,2),SUBSTR(Product,4,2)) FROM tablename;
depending on whether you're working through ODBC or not.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

How about the DB2 REPLACE command.

REPLACE(Product, ' ', '')

I also suggest that you don't use user defined SQL, instead stick to generated SQL and put the REPLACE command into the Derivation field on your columns tab, you will then see it turn up in your generated SQL tab. Generated SQL is usually easier to maintain over time then user defined SQL as it is easy to add and remove columns. You can then save the column definition with the REPLACE statements in your saved table definition for use by other jobs.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's a good day, I've learned something new. Yay! :)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mandyli
Premium Member
Premium Member
Posts: 898
Joined: Wed May 26, 2004 10:45 pm
Location: Chicago

Post by mandyli »

In DB2 itself " REPLACE" is there please replace .
Post Reply