Home » SQL & PL/SQL » SQL & PL/SQL » Extract data from query insert in table, if Null insert other values (Oracle 9i Windows)
Extract data from query insert in table, if Null insert other values [message #302027] Fri, 22 February 2008 13:59 Go to next message
suzyque54
Messages: 14
Registered: December 2006
Junior Member
I need help with this query. I am trying to extract data with query1 and load the results to a table1. However, sometimes the results or query1 are null and then I want to load other values so my table is not missing data especially a date as I need an entry for each day. Both the query and the table have 3 columns, ENDDATE, ID, and COUNT.
1 INSERT
2 WHEN (ENDDATE IS NULL) THEN
3 into table1 (ENDDATE, ID, COUNT)
4 VALUES(TO_CHAR(SYSDATE, 'MM/DD/YYYY')),'NONE', 0)
5 ELSE
6 into table1 (ENDDATE, TID, CHRONICCOUNT)
7 VALUES (ENDDATE, ID, COUNT)
8* SELECT * from query 1

SQL> /
VALUES(TO_CHAR(SYSDATE, 'MM/DD/YYYY')),'NONE', 0)

ERROR at line 4:
ORA-00928: missing SELECT keyword

Thanks for your help this is driving me crazy!
Re: Extract data from query insert in table, if Null insert other values [message #302034 is a reply to message #302027] Fri, 22 February 2008 14:20 Go to previous message
Michel Cadot
Messages: 64107
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use decode or case in your query1 to return the values you want depending on the null/not null case.
Then you just have to do an "insert select".

Otherwise the statement is INSERT FIRST and not INSERT alone.

Regards
Michel
Previous Topic: Retrieving rows for which SUM(qty) equals to a specified value ?
Next Topic: Query to Know Product Languages of my database..
Goto Forum:
  


Current Time: Mon Dec 05 04:45:38 CST 2016

Total time taken to generate the page: 0.10584 seconds