Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Slcting addnal column outside DISTINCT in a select query

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

New User


Joined: 27 Dec 2005
Posts: 58

PostPosted: Mon Jun 09, 2008 2:27 pm    Post subject: Slcting addnal column outside DISTINCT in a select query
Reply with quote

We are currently modifying a CICS-DB2 prod pgm which has a main menu map which shows address summary and then on selecting S on the record displays a full address on the next screen.

MAIN MAP:
OPTION NAME TRADE ZIP CODE CITY
S DAVID XXXXXXXX 08012 KANSAS

DETAIL MAP(XCTL from MAIN MAP):This would have the complete address.

To achieve this we had a prod query which looks like:
SELECT DISTINCT(For the main map summary)
a.name
,a.trade
,a.zip code
,a.city
FROM table1 a
,table2 b
WHERE a.key = b.key(KEY would be a selection variable entered on the main map).We had some issues with -811 coming on the detail screen since a particular NAME had multiple addresses in several LOCS in same city.

Hence we are trying to change this query to also send the LOC NUMBER to the detail program:
SELECT DISTINCT
a.name
,a.trade
,a.zip code
,a.city
,a.LOCNUM
this would help in uniquely identifying the address.

However when we do this the DISTINCT on the main map is getting affected.
EX:
DAVID XXXXXXXX 08012 KANSAS
DAVID XXXXXXXX 08012 KANSAS

Suppose we had these 2 addresses fetched in main map query then because of DISTINCT it would have sent 1 row to the map but now it would send 2 rows since we are also fetching the loc num.Since the loc num is not required on the map it ends up looking like entire duplicate rows on the main map.

Is there any way we can get the loc number in the same query without affecting the original 4 columns.So we should get 1 row and also get the loc num for the next program.
Back to top
View user's profile Send private message

stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jun 09, 2008 6:50 pm    Post subject:
Reply with quote

Quote:

Is there any way we can get the loc number in the same query without affecting the original 4 columns.So we should get 1 row and also get the loc num for the next program.


The short answer to this is: No there is not a way to accomplish this.
---------------------------------------------------------------------------------------
How is the user to know if LOCNUM 1 or LOCNUM 4 is the one they should be choosing?

Say you have this in your table
Code:

Bob   plumber   90210   Beverly Hills   1
Bob   plumber   90210   Beverly Hills   2
Bob   plumber   90210   Beverly Hills   3
Bob   plumber   90210   Beverly Hills   4
Bob   plumber   90210   Beverly Hills   5

Am I correct in stating that you only want the following for your main screen?
Code:

Bob   plumber   90210   Beverly Hills   5

Because by using DISTINCT in your first query you have no idea which LOCNUM you are getting. It could be 1,2,3,4, or 5 the result is indeterminate.

If you don't SELECT LOCNUM initially and do a select after the user has made a selection on the screen, how will you know which one is the correct LOCNUM if they are all the same except for the LOCNUM?
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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us