Hello, I am relatively new to the world of SQL and Toad. I am trying to use TD Automation to loop over the rows of an initial query to create excel files for each sub-analysis.
For some background: I’m using Toad 3.6, Oracle DB.
My initial query looks at a large database of medical claim data, and sums up all of the bills for a given claim. To make it manageable I am trying to take the top XX most expensive claims:
SELECT * FROM
(SELECT JCN, SUM(TOT_CHARGE_PER_BILL) FROM
(SELECT JCN, TOT_CHARGE_PER_BILL FROM MED_BILLS WHERE TOT_CHARGE_PER_BILL < 50000)
GROUP BY JCN
ORDER BY SUM(TOT_CHARGE_PER_BILL) DESC)
WHERE ROWNUM <= 10
The output from this initial query is named TOP_CLAIMS_SQL in the automation setup. My goal is to look at the details for each claim number(JCN) within my subset.
I then followed the tutorials and used the “Select to File” to write the output. It seemed to mostly work(numbering was not making sense) but when I tried to use a JOIN to get some missing data(names):
SELECT a.JCN,b.FIRST_NAME, b.LAST_NAME FROM MED_BILLS a
JOIN PROVIDERS b on a.IDN=b.IDN
WHERE (a.JCN = :TOP_CLAIMS_SQL.JCN)
it now throws the following error:
File_1 - ORA-01722: invalid number
I’m wondering if perhaps I’m using the WHERE ROWNUM <=XX incorrectly(I’ve also tried changing the exact value for troubleshooting), or if the problem is elsewhere.
If I run this in the SQL editor and manually define the JCN e.g WHERE a.JCN = ‘number’ it works, but not in the Automation Tool.
Here is the entire error log:
12:02:54 PM Thread (23) Export Started [5/4/2017 12:02:54 PM]
12:02:54 PM Thread (23) Export using connection: ####(removed by me)
12:02:54 PM Thread (23) Export using connection: ####
12:02:54 PM Thread (23) Export Wizard: Building object list
12:02:54 PM Thread (23) Exporting Data (1 of 1)
12:02:54 PM Thread (23) Object SQL Query started.
12:02:55 PM Thread (6) InternalReadBackground - start
12:02:57 PM Thread (6) InternalReadBackground - exception Exception occurred in other process
12:02:57 PM Thread (6) InternalReadBackground - stack at Dell.NamedPipeRPC.MessagePumpClient.Invoke(Delegate target, Object[] parameters)
at Quest.Toad.Db.ConnectionProxy.ProxyConnectionCommand.ExecuteReader()
at Quest.Toad.Db.ToadDataAdapter.InternalReadBackground()
12:02:57 PM Thread (24) DoneReadTreadWriter
12:02:57 PM Thread (24) DoneReadThreadWriter finally - adapter.RowsRead 0
12:02:57 PM Thread (23) Object SQL Query finished with error: ORA-01722: invalid number
12:02:57 PM Thread (23) at Devart.Data.Oracle.a1.c(Int32 A_0)
at Devart.Data.Oracle.cs.a(Int32 A_0, cc A_1)
at Devart.Data.Oracle.OracleCommand.InternalExecute(CommandBehavior behavior, IDisposable disposable, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at Quest.Toad.Db.ConnectionProxy.ProxyConnectionCommand.ActualExecuteReader(Object[] parameters)
12:02:57 PM Thread (23) Export Finished [5/4/2017 12:02:57 PM]
Thanks in advance!
Gabe