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
 

 

Conditional selection of DB2 table columns

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Feb 16, 2007 11:14 am    Post subject: Conditional selection of DB2 table columns
Reply with quote

Hi,
I want to update few columns of a DB2 table through COBOL program.
But which columns to update will depend upon the condition.
Eg.
IF (condition)
Update columns 1,2,3 of Db2 Table
Else
Update columns 2 and 3 of same table.
End-if.

Now, I can do it by using 2 SQL queries, but my question is can it be done by using single SQL query (by checking condtion inside the query, or something like that) ?

--Parag
Back to top
View user's profile Send private message

prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Fri Feb 16, 2007 11:31 am    Post subject:
Reply with quote

Parag,

In u r IF part u r updating 3 cols 1,2,3 and in u else part u r updating 2,3 col, tell me one thing when, u update 2 and 3 cols in the else part r u storing the value of col 1 in any host variable from any previous query. If your ans is yes u can use a single query to update. the concept is to update 3 cols 1,2,3 c this logic

IF COND
Move col1 to 1
move col2 to 2
move col3 to 3
go to update
ELSE
Move prev-value of col1 to 1
move col2 to 2
move col3 to 3
go to update
END-IF.

And in your update para give a query to update all the three cols.



Cheer's,

Thamilzan.
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Feb 16, 2007 11:41 am    Post subject: Re: Conditional selection of DB2 table columns
Reply with quote

Hi prav_06,
Thanks for your reply !

No, I am not storing the values of columns anywhere. In fact I only update the table and do not select it. The values those are updated are external.

--Parag
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Fri Feb 16, 2007 12:02 pm    Post subject:
Reply with quote

Parag,
if ya don't know the value of the 1 st col, when u updating the col. for your else cond, I don think that u can use a single query for that , the concept is use a update statement to update all the 3 col, and the value of the 1st col must not change when the else part is executed, tough ask .. lets wait an c what other's think about this.

Cheer's,

Thamilzan.
Back to top
View user's profile Send private message
baldi

New User


Joined: 16 Jun 2005
Posts: 13
Location: Amsterdam

PostPosted: Fri Feb 16, 2007 2:24 pm    Post subject: Re: Conditional selection of DB2 table columns
Reply with quote

hey, why don't you try CASE command, it will be something like this :

UPDATE "XXXXXX"
SET A =
CASE WHEN <CONDITION> THEN "NEW vALUE"
ELSE A
SET B = "NEW B"
SET C = "NEW C"

It will update first column only when the condition is true.
I think it should solve your query.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts unload data from table with lob columns farhad_evan DB2 1 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


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