MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query for formatting the column

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Fri Aug 31, 2007 3:16 am    Post subject: Query for formatting the column Reply with quote

I have table Employee with two fields
Name[x(20)] and Salary[9(10)]
The data will be as follows

Code:
NAME                SALARY
----+----1----+----2----+----
RAKESH-                125000
RAVI-                   90000
MADHU SUDHAN-           10000
SOMASHEKAR-             13457

I require a query which will format the employee name by removing "-"
which is at end of each name and display the data as follows

Code:
NAME                SALARY
----+----1----+----2----+----
RAKESH                 125000
RAVI                    90000
MADHU SUDHAN            10000
SOMASHEKAR              13457

Please help me in achieving this.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Aug 31, 2007 3:36 am    Post subject: Reply with quote

psmadhusudhan,

Try this.

Code:

SELECT REPLACE(NAME,'-',' ') 
      ,SALARY                 
  FROM TABLE                     
  ;         


Check this link for a detailed explanation of the scalar function replace

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQJ12/3.2.89

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Fri Aug 31, 2007 8:06 am    Post subject: Reply with quote

Thanks Kolusu.

I have one question, I am not getting mails when a reply is posted for my post even though I am selecting 'Notify me when a reply is posted'.
Can you help me in this.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Aug 31, 2007 10:30 am    Post subject: Reply with quote

Quote:

I have one question, I am not getting mails when a reply is posted for my post even though I am selecting 'Notify me when a reply is posted'.


psmadhusudhan,

The feature is working fine. You should be getting the emails to the mail id specified in the Profile.

http://www.mvsforums.com/helpboards/profile.php?mode=editprofile

Make sure you have the right address. If you have the right email address then may be your client is blocking the emails.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
bstillwa
Beginner


Joined: 01 Nov 2004
Posts: 23
Topics: 6
Location: NJ

PostPosted: Fri Aug 31, 2007 11:45 am    Post subject: Reply with quote

I believe that using REPLACE will replace all occurrences of a dash, so if a name contains a dash in other than the last position, then that dash will also be removed. The question was for only removing a trailing dash.
_________________
Bev.
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Fri Aug 31, 2007 12:02 pm    Post subject: Reply with quote

Try this:

Code:

select  last_name
       ,case substr(last_name,length(rtrim(last_name)),1)
          when '-' then substr(last_name,1,length(rtrim(last_name)) - 1)
          else last_name
        end
  from  tbl_01
Back to top
View user's profile Send private message
advoss
Beginner


Joined: 23 Aug 2005
Posts: 26
Topics: 0

PostPosted: Fri Aug 31, 2007 12:02 pm    Post subject: Reply with quote

how about
select left(name,length(name)-1) as name,salary
from table;

or

select substr(name,1,length(name)-1) as name,salary
from table;
_________________
Alan Voss
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Fri Aug 31, 2007 12:15 pm    Post subject: Reply with quote

Easier yet is the STRIP function.

Code:

select  last_name
       ,strip(last_name,t,'-')
  from  tbl_01


(I'm running UDB on AIX and can't test this because STRIP isn't supported, but I think the syntax is correct for DB2 for z/OS)
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Fri Aug 31, 2007 2:51 pm    Post subject: Reply with quote

try strip(rtrim(name),t,'-')
Back to top
View user's profile Send private message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Mon Sep 03, 2007 12:09 am    Post subject: Reply with quote

Thank you all for your replies Very Happy
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group