Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Query on SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Mar 27, 2015 12:21 pm    Post subject: Query on SQL
Reply with quote

Hi,

I have an issue while comapring account number column in CHARACTER format with that of an account number column in INTEGER format(leading zeros are suppressed) via SQL.

The account numbers are not picked correctly.

(eg. 01234567 or 00123456 etc.,). Thease are some account numbers when comparsion its not working.

Please help me on what modification should I do so that the comparison works perfectly in SQL between CHARACTER and INTEGER.
Back to top
View user's profile Send private message

abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Fri Mar 27, 2015 12:52 pm    Post subject:
Reply with quote

I tried with the below statement but its not working,

SUBSTR(A.ACCOUNT_NUMBER,7,8)=CHAR(B.ACCOUNT_NO).

scenario:
Account number 00123456 (which is of CHAR definition) is not macthing with 123456 (which is of INT definition) with that of the other table.

I cannot determine position using substr as it changes. So is there a way out to supress the zeros and check it in SQL.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Fri Mar 27, 2015 4:26 pm    Post subject:
Reply with quote

Hi,

Use CAST function to convert Character column to Integer and then use for comparison

Regards,
Chandan
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Thu May 07, 2015 1:01 pm    Post subject:
Reply with quote

For optimization, CAST does not work. It takes more time. So can we any other option to comparison. I used TRIM . even then it takes more time.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu May 07, 2015 1:23 pm    Post subject: Reply to: Query on SQL
Reply with quote

You have a poor setup, so just forget about any optimisation.
You will have to live with what You will get as long as it provides the proper result.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Fri May 08, 2015 3:26 pm    Post subject:
Reply with quote

DB2 luw : trim(leading '0' from MyCharColumn)
or
DB2 zOS : LTRIM(MyCharColumn, '0'),
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts SQL Query optimization. arunsoods DB2 12 Sun Sep 04, 2016 6:27 am
No new posts Query on BLSR Nileshkul JCL & VSAM 2 Sat Aug 13, 2016 5:18 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us