View previous topic :: View next topic
|
Author |
Message |
ParagChouguley
Active User
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
ParagChouguley
Active User
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
baldi
New User
Joined: 16 Jun 2005 Posts: 13 Location: Amsterdam
|
|
|
|
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 |
|
|
|