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

VALUE function in SQL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Jan 27, 2010 6:48 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Jan 27, 2010 7:08 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Jan 27, 2010 7:20 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top