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 

Help needed in gettting the right query...

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


Joined: 10 Jan 2007
Posts: 33
Topics: 12

PostPosted: Tue Jun 05, 2007 6:19 am    Post subject: Help needed in gettting the right query... Reply with quote

I have a table called aff_gdg

it has two columns aff-id - integer , gdg-id- char 09

here in gdg-id we store numeric data items..

My intention is to pull those gdg-id's whose first 5 bytes or last 5 bytes equals any of the aff-id column values

this is my data in table
Code:

---------+---------+---
     AFF_ID  GDG_ID   
---------+---------+---
         55           
         55
         15      55   
      54321           
         14  000014   
      54321  54321     


I want my output as
Code:

---------+---------+---
     AFF_ID  GDG_ID   
---------+---------+---
         55           
         55           
         15    55     
         14    14   
      54321  54321     



But what i am getting is
Code:

---+---------+-------
 AFF_ID      GDG_ID   
---+---------+-------
   15           55   
   14           14   
54321        54321     



the query am using is
Code:

--------+---------+---------+---------+---------+---------+-----
 SELECT G.AFF_ID aff-id, INTEGER(G.gdg_id) COL1     
 FROM XAD13.AFF_Gdg G                                   
               WHERE ( SUBSTR(G.gdg_id,1,5) IN         
                       (SELECT CHAR(R.AFF_ID)               
                        FROM XAD13.AFF_Gdg R)           
                                                               
                 OR    SUBSTR(G.gdg_id,1,5,5,5) IN         
                       (SELECT CHAR(R.AFF_ID)               
                        FROM XAD13.AFF_Gdg R));


Help me to resolve the issue
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Jun 05, 2007 6:50 am    Post subject: Reply with quote

Quote:

whose first 5 bytes or last 5 bytes equals any of the aff-id column values


how does this row fit into your requirements?

Code:

         15      55   


15 is stored as
Code:

000000015


and the last 5 digits of it is

Code:

00015


and I don't see 15 in the string under GDG_ID. how did you pick that?

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


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Jun 05, 2007 7:48 am    Post subject: Reply with quote

arshadh,
Quote:
pull those gdg-id's whose first 5 bytes or last 5 bytes equals any of the aff-id column values


that is what you are receiving! what you want is those plus any aff_id that equals any gdg_id regardless of the associated gdg_id column value - which maybe a UNION of the reverse 'IN' is required. but, I am lost because I have no idea how the SQL is functioning with hyphens and underscores intermixed in your SQL.
Quote:
SELECT G.AFF_ID aff-id, INTEGER(G.gdg_id) COL1

and what is this?:
Quote:
SUBSTR(G.gdg_id,1,5,5,5)


be nice if you would include in your post the SQL that you are actually running. Or is DB2 so forgiving that you can have such syntax errors?
_________________
Dick Brenholtz
American living in Varel, Germany
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