Home » SQL & PL/SQL » SQL & PL/SQL » insert in seperate columns depending on data (Oracle 9i)
insert in seperate columns depending on data [message #408212] Mon, 15 June 2009 05:55 Go to next message
sumithaswar
Messages: 6
Registered: June 2009
Junior Member
Hi,

Consider the following query

insert into table1 (a,b,c)
select x , y , z
from table2

the logic is as follows

if x is null then insert y in b
if x is not null then insert x in a
Re: insert in seperate columns depending on data [message #408217 is a reply to message #408212] Mon, 15 June 2009 06:15 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Look into the syntax of the DECODE function
Re: insert in seperate columns depending on data [message #408218 is a reply to message #408212] Mon, 15 June 2009 06:16 Go to previous messageGo to next message
bonker
Messages: 402
Registered: July 2005
Senior Member
insert into table1 (a,b,c)
select x , case when x is null then y end new_y, z 
from table2


[Update] Oops, I published a solution which is not recommended as per forum guidelines, due apologies for that. I some how feel that OP has oversimplified his problem

[Updated on: Mon, 15 June 2009 06:18]

Report message to a moderator

Re: insert in seperate columns depending on data [message #408221 is a reply to message #408218] Mon, 15 June 2009 06:28 Go to previous message
sumithaswar
Messages: 6
Registered: June 2009
Junior Member
Thanks,
it worked.
Previous Topic: Procedure to update the close_day
Next Topic: Reading Excel File columns
Goto Forum:
  


Current Time: Mon Dec 05 13:21:15 CST 2016

Total time taken to generate the page: 0.16123 seconds