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 

Using "LIKE" predicate

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


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Sun Nov 14, 2004 9:52 am    Post subject: Using "LIKE" predicate Reply with quote

Hi,

I need help in using "LIKE" predicate. Requirement is as follows.

I have a cobol program which inserts the following 01 level variable in to a column TBL_PKEY of DB2 table T1 which is defined C(20).

Code:
01  PRIMARY-KEY.
    05  ACCOUNT-NO  PIC S9(9) COMP.
    05  CURRENCY  PIC X(003).


Say ACCOUNT-NO = 40022154 and CURRENCY = CHF

Then TBL_PKEY is inserted with some value having special characters. If I copy that value and put it in one dataset and say 'HEX ON', I am getting the following data.

Code:
06B8CCC
220A386


Now my requirement is if any column of the primary key is given, is it possible to retrieve the row using the 'LIKE' predicate through a BATCH SPFUI.

If the entire primary key is given, I am using the following spufi to retrieve the data.

Code:
SELECT  C1, C2
     FROM  T1
 WHERE  TBL_PKEY  = X'0262B08AD1D7E8' ;
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Sun Nov 14, 2004 7:15 pm    Post subject: Reply with quote

psridhar,

What is the column definition of your primary key?. Is it defined as character? If it is defined as character then you can use substr function to extract the first 4 bytes

Hope this helps...

Cheers

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


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Mon Nov 15, 2004 8:20 am    Post subject: Reply with quote

Hi Kolusu,

Thank you for the help.

DB2 column T1.TBL_PKEY is defined as CHAR. Let me explain my requirement again. Say T2.ACCOUNT-NO and T2.CURRENCY are the primary keys of the table T2. T1.TBL_PKEY will store the primary key of the table T2. If both ACCOUNT-NO and CURRENCY are given as inputs to T1, then following SPUFI will retrieve the row.

Code:
SELECT  TBL_PKEY
  FROM  T1
 WHERE  TBL_PKEY  = X'0262B08AD1D7E8' ;


Say only CURRENCY is given then my spufi should be some thing simillar to the below one.

Code:
SELECT  TBL_PKEY
  FROM  T1
WHERE  TBL_PKEY  LIKE %X'D1D7E8'% ;


Say T1.TBL_PKEY is storing primary key of a table T2 having 4 columns as primary key. The user can give any one of the primary key columns of table T2 or entire primary key value of the table T2. If entire primary key value is given, I can convert it in to HEX and use the where caluse with "=" as below.

Code:
WHERE  TBL_PKEY  = X'0262B08AD1D7E8' ;



If any one of the primary key columns of table T2 is given then how to retrieve the row in table T1.

Hope now my problem is clear to you.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Nov 15, 2004 8:51 am    Post subject: Reply with quote

Psridhar,

Try this

Code:

SELECT *                                     
  FROM T1                                     
  WHERE HEX(SUBSTR(TBL_PKEY,1,4)) LIKE 'D1D7E8%'
  ;                                           


Hope this helps...

Cheers

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


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Mon Nov 15, 2004 9:11 am    Post subject: Reply with quote

Hi Kolusu,

Thank you very much for the help. It works fine.

Sridhar P
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