IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Conditional selection of DB2 table columns


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Remote Unload of CLOB Columns DB2 6
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top