Friday, 15 June 2012

sql - updating a table upon two conditions from the same table -



sql - updating a table upon two conditions from the same table -

i have table columns book, startyear, endyear , author.

i need update startyear , endyear columns simultaneously depending on next conditions,

startyear = endyear startyear=0 , endyear != 0 endyear = startyear endyear =0 , startyear != 0

it possible

update table set startyear = endyear startyear=0 , endyear<>0; update table set endyear = startyear endyear =0 , startyear<>0;

how can write these 2 queries in single query?

update table set startyear = case when startyear = 0 , endyear<>0 endyear else startyear end, endyear = case when endyear = 0 , startyear <> 0 startyear else endyear end startyear = 0 or endyear = 0;

sql oracle

No comments:

Post a Comment