IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to truncate unused spaces in a column during select


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
roopannamdhari
Warnings : 1

New User


Joined: 14 Sep 2006
Posts: 71
Location: Bangalore

PostPosted: Tue Jul 15, 2008 12:26 pm
Reply with quote

Hi,
I am having one table1 .

table1
column1 - char(40)
column2 - char(40)

column1 column2
abcd efh
abcd efh

On execution of following query I am getting output as

Select * from table1

OUTPUT:
column1 column2
abcd(36 spaces) efh(37 spaces)

Please let me know how to truncate unused spaces in a column during select statement.


Thanks,
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Tue Jul 15, 2008 12:29 pm
Reply with quote

Roopa,

Try STRIPing the column.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 15, 2008 12:43 pm
Reply with quote

That is all well and good, but what is the destination field for the column?

you will have to have a host variable large enough to receive the value returned by the select. I doubt that all values contained in these two columns (bytes > spaces) are of the same length. So, eventhough you remove spaces, you will have them again in the host varibale. These columns do not appear to be defined as varchar.

performing the db2 strip is a waste of time. What is your final destination field? Unless you are using PL/1, C or Java as your application, COBOL does not lend itself to variable length fields.

what actually do you need to do?
Back to top
View user's profile Send private message
roopannamdhari
Warnings : 1

New User


Joined: 14 Sep 2006
Posts: 71
Location: Bangalore

PostPosted: Tue Jul 15, 2008 2:40 pm
Reply with quote

Hi Murali,
Can u please breif me regarding Striping THE COLUMN

Thanks,
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Jul 15, 2008 2:46 pm
Reply with quote

as a general point there is no reason to blank_strip a variable
an area large enough to contain the whole string must be provided anyway

th only reasonable ( but as usual it depends ) alternative is to use, IIRC, LTRIM to left align things ( for a quick display )

but to give the best answer the whole requirements must be clear
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jul 15, 2008 8:04 pm
Reply with quote

Hello,

It would be better to focus on the replies that may help with your requirement than the replies that sound like what you believe you want to hear. . .

As has been repeated, STRIP will accomplish little as you still need a variable of proper length. . .

As has also been mentioned, if you explain your requirement (rather than some possible solution), someone here may have suggestions.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Jul 16, 2008 9:45 am
Reply with quote

Why is there an assumption the output is in a program and has a destination field/variable in said program? The way the data was presented, it could be an ad hoc query run against the db and he wants to copy/paste it into another app.

Guess we'll have to see, but it the O/P made it seem like STRIP may do the job. Does DB2 also have the TRIM(Col1) syntax?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
Search our Forums:

Back to Top