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
 

 

-811 in db2 CASE Statement

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

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Tue Sep 16, 2014 5:23 pm    Post subject: -811 in db2 CASE Statement
Reply with quote

Hi ,

I am trying to execute the below query
Code:
SELECT * FROM USI.TSSIMB
WHERE SIMB_CD_BP IN
(CASE
WHEN  (SELECT COUNT(*) FROM USI.TSSIMD
WHERE SIMD_ID_SIM = 23
AND SIMD_TYPE ='BP') > 0
THEN
(SELECT SIMD_VALUE1 FROM USI.TSSIMD
WHERE  SIMD_TYPE ='BP'
AND    SIMD_ID_SIM = 23)
ELSE
(SELECT DISTINCT SIMB_CD_BP FROM USI.TSSIMB)
END);


and i am getting sqlcode -811 with below description

Code:
DSNT408I SQLCODE = -811, ERROR:  THE RESULT OF AN EMBEDDED SELECT STATEMENT OR
A SUBSELECT IN THE SET CLAUSE OF AN UPDATE STATEMENT IS A TABLE OF
MORE THAN ONE ROW, OR THE RESULT OF A SUBQUERY OF A BASIC PREDICATE
IS MORE THAN ONE VALUE


Please Guide me , how to solve this issue
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Tue Sep 16, 2014 6:13 pm    Post subject: Reply to: -811 in db2 CASE Statement
Reply with quote

Use DISTINCT as per your last line of the query. If that is not an option and you need one row then add more WHERE conditions.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Sep 17, 2014 12:12 am    Post subject:
Reply with quote

use
Code:
 FETCH FIRST ROW ONLY
but it looks like you need to place this under cursor as you have a IN operator which meant to get more than 1 row.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Mon Oct 06, 2014 2:51 pm    Post subject: Re: -811 in db2 CASE Statement
Reply with quote

A case can only return 1 value.
I think you want
Code:
SELECT * FROM USI.TSSIMB
where  SIMB_CD_BP IN
   (SELECT SIMD_VALUE1 FROM USI.TSSIMD
     WHERE  SIMD_TYPE ='BP'
       AND SIMD_ID_SIM = 23)
or
 not exists (SELECT SIMD_VALUE1 FROM USI.TSSIMD
           WHERE  SIMD_TYPE ='BP'
              AND SIMD_ID_SIM = 23)
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Oct 08, 2014 3:46 am    Post subject:
Reply with quote

GuyC , I think you might wants to consider
Code:
SELECT DISTINCT SIMB_CD_BP FROM USI.TSSIMB
condition as well. But I may be missing something.

He already might have got the solution but can also try below IF HE HAS A COBOL PROGRAM.

Code:
SELECT col1,col2.....,'Y' FROM USI.TSSIMB
WHERE SIMB_CD_BP IN
(SELECT SIMD_VALUE1 FROM USI.TSSIMD
WHERE  SIMD_TYPE ='BP'
AND    SIMD_ID_SIM = 23)
UNION
SELECT col1,col2.....,'N' FROM USI.TSSIMB
WHERE SIMB_CD_BP IN
(SELECT DISTINCT SIMB_CD_BP FROM USI.TSSIMB)

FETCH FIRST ROW ONLY;


And then check for Y and N in COBOL and process accordingly. I mean if Y is found then ignore 'N' else process 'N' record.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Wed Oct 08, 2014 5:23 pm    Post subject:
Reply with quote

Hi,

I guess OP want to give 1st preference to below criteria
Code:
SELECT SIMD_VALUE1 FROM USI.TSSIMD
WHERE  SIMD_TYPE ='BP'
AND    SIMD_ID_SIM = 23


if does not find anything with above criteria then only go for below criteria
Code:
SELECT DISTINCT SIMB_CD_BP FROM USI.TSSIMB


Ranjan, Can you please confirm this is what your requirement is?

May be I am missing something, but GuyC's query will return rows with both conditions.

Rohit's query seems to work fine if row with 'Y' come on top always as a result of UNION query.

But my question to OP is why DISTINCT is required there as anyways with IN clause you will return multiple rows for given SIMB_CD_BP if there are any in table.

Correct me if I am missing anything

Regards,
Chandan
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Thu Oct 09, 2014 5:28 am    Post subject:
Reply with quote

Quote:

But my question to OP is why DISTINCT is required there as anyways with IN clause you will return multiple rows for given SIMB_CD_BP if there are any in table.


Right, Thats is why in my first reply I suggested this, Let us wait for TS to reply. However, DISTINCT is to get unique and multiple SIMB_CD_BP ( so that should be fine for him per his requirement)

Quote:
Rohit's query seems to work fine if row with 'Y' come on top always as a result of UNION query.


by adding
Code:
order by 2 desc
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Thu Oct 09, 2014 4:13 pm    Post subject:
Reply with quote

Quote:

However, DISTINCT is to get unique and multiple SIMB_CD_BP ( so that should be fine for him per his requirement)


my concern with DISTINCT was, irrespective of having distinct or not query result not going to change, but it will impact on performance with having distnict

Yes lets see if TS replies
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Fri Oct 10, 2014 4:38 am    Post subject:
Reply with quote

Quote:
my concern with DISTINCT was, irrespective of having distinct or not query result not going to change, but it will impact on performance with having distnict

Why will it not change the result? If I remove the DISTINCT then TS would be getting unwanted duplicate rows for same SIMB_CD_BP.

But the whole point is unless TS use the cursor or say 'FETCH FIRST ROW ONLY' to the query ,DQLCODE -811 would certainly be persist.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Sat Oct 11, 2014 11:43 pm    Post subject:
Reply with quote

Hi Rohit,

Let me try to explain my view with distinct for below qurey
Code:
WHERE SIMB_CD_BP IN
(SELECT DISTINCT SIMB_CD_BP FROM USI.TSSIMB)


Let say table has following data for SIMB_CD_BP

Code:
SIMB_CD_BP
1
1
2
2
3
3
3


Then for above data below both WHERE clause will return the same set of rows

Code:
WHERE SIMB_CD_BP IN
(1,2,3)

WHERE SIMB_CD_BP IN
(1,2,3)


Kindly correct me if I missing anything here as I don't have system to check right now.

Regards,
Chandan
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Sun Oct 12, 2014 12:11 am    Post subject:
Reply with quote

Some more information on duplicates in IN clause

http://ibmmainframes.com/about42673.html

Regards,
Chandan
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Mon Oct 20, 2014 5:38 pm    Post subject:
Reply with quote

did anyone notice this :
Code:
SELECT * FROM mytable WHERE mycolumn IN
(SELECT mycolumn FROM mytable)

I'm pretty sure this will always be true
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 -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
This topic is locked: you cannot edit posts or make replies. Updating value of key using rewrite s... ParminderKumar COBOL Programming 4 Thu Aug 04, 2016 12:46 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm


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