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
 

 

VALUE function in SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
V K R A S Srinivas

New User


Joined: 02 Jan 2007
Posts: 9
Location: Hyderabad

PostPosted: Wed Jan 27, 2010 6:40 pm    Post subject: VALUE function in SQL
Reply with quote

Hi !

I have requirement as below:

Table A with Cloumns AC1 CHAR(10), AC2 SMALLINT, AC3
Table B with Cloumns BC1 SMALLINT, BC2 SMALLINT, BC3

I have used VALUE function in SELECT Clause to retrieve all the rows from A & B Tables with AC2 and BC2 are equal as below:

SELECT VALUE(SUBSTR(AC1, 1, 4), '0'), AC2
FROM TABLE1 A
TABLE2 B
WHERE AC2 = BC2.

Now I Have to retrieve only those rows where the first 4 characters of AC1 is equal to BC1. But as AC1 and BC1 are with different datatypes, I am getting -401 sqlcode when I use the following sql:

SELECT VALUE(SUBSTR(AC1, 1, 4), '0'), AC2
FROM TABLE1 A
TABLE2 B
WHERE AC2 = BC2
AND BC1 IN VALUE(SUBSTR(AC1, 1, 4), '0')

So Could you please suggest anyother way to implement this.

Thank you in advance
Srinivas Vaddadi
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Wed Jan 27, 2010 6:48 pm    Post subject: Reply to: VALUE function in SQL
Reply with quote

Quote:
So Could you please suggest anyother way to implement this.


not only they are different datatypes, but they do not really bear the slightest resemblance
and even if it is possible to do some casting to an homogeneous representation it would be anyway considered ...
poor application design, at least

the best suggestion would be to tar and feather the application design team

and...
what about the fact that chars are left aligned, numbers are right aligned
Back to top
View user's profile Send private message
V K R A S Srinivas

New User


Joined: 02 Jan 2007
Posts: 9
Location: Hyderabad

PostPosted: Wed Jan 27, 2010 7:04 pm    Post subject:
Reply with quote

Hi Enrico,

THank you for the quick response.

We are sure that the first 4 chars of the field AC1 is getting populated with integer values only. I am not sure what can be done.

Thank you
Srinivas Vaddadi
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Wed Jan 27, 2010 7:08 pm    Post subject: Reply to: VALUE function in SQL
Reply with quote

what if the bc1 contains a number less than 1000 ??
what about the possible leading zeroes in the AC1 column??
Back to top
View user's profile Send private message
V K R A S Srinivas

New User


Joined: 02 Jan 2007
Posts: 9
Location: Hyderabad

PostPosted: Wed Jan 27, 2010 7:15 pm    Post subject:
Reply with quote

Hi Enrico,
BC1 contains a max value of 25 only. It cannot contain more than 25.

Thank you
Srinivas Vaddadi
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Wed Jan 27, 2010 7:20 pm    Post subject: Reply to: VALUE function in SQL
Reply with quote

if bc1 has a max value of 25, how can You expect to match it against a 4 bytes value

there are a few things unclear in the explanation and/or the requirements and/or the design
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Jan 28, 2010 8:58 pm    Post subject:
Reply with quote

you can't substring an integer. first convert it with the available functions like DIGITS or CHAR , ...

I'm not sure you understand what the function VALUE() does, it has nothing to do with a numeric value within a char-column. but everything with nullable columns.

google ,read up and experiment on DB2 functions.
Once you find the correct function, I'm sure you can solve this with the case-specific answers to the questions Enrico poses.
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
No new posts What is the Extract Function in JCL dharmaraok JCL & VSAM 3 Wed Jun 14, 2017 9:12 am
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am


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