Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel - sql to oracle database

Posted on 2013-06-14
10
Medium Priority
?
372 Views
Last Modified: 2013-06-24
Hi,
The sql query work perfectly to query the data from oracle database via Ms Access.
However, the moment i copy the exactly sql query into excel VBA. it turn out not working.
The error message i get is from excel VBA as follows

Run-time error '-2147467259 (80004005)
Automation error
Unspecified error
   

   Dim conn As New ADODB.Connection
    Dim connString
    connString = "DSN=XXX;Uid=XXX;Pwd=XXX"
    
    Dim rsRecords As New ADODB.Recordset
    Dim sqlStr As String
    
 sqlStr = "SELECT TPJ_WO.CUSTOMERPONO, TPJ_SI.SHIPMENTNO, TPJ_SDETAILS.ITEMCODE, TCM_MASTER.ITEMNAME, TPJ_WO.WORKORDERNO, TPJ_WO.ITEMNAME, TPJ_WO.TARGETPOWER, TPJ_SDETAILS.SHIPMENTQUANTITY, TCM_FGMASTER.SHIPPINGTYPE, TPJ_SI.SHIPMENTDATE"

sqlStr = sqlStr & "FROM (((TPJ_SI INNER JOIN TPJ_SDETAILS ON "
sqlStr = sqlStr & "TPJ_SI.SHIPMENTNO = TPJ_SDETAILS.SHIPMENTNO) "
sqlStr = sqlStr & "INNER JOIN TPJ_WO ON TPJ_SDETAILS.LOTNO = TPJ_WO.WORKORDERNO)"
sqlStr = sqlStr & "INNER JOIN TCM_MASTER ON TPJ_SDETAILS.ITEMCODE = TCM_MASTER.ITEMCODE)"
sqlStr = sqlStr & "INNER JOIN TCM_FGMASTER ON TPJ_SDETAILS.ITEMCODE = TCM_FGMASTER.FINALPRODUCTCODE;"
    
    conn.Open connString
    rsRecords.CursorLocation = adUseClient
    rsRecords.Open sqlStr, conn, adOpenForwardOnly, adLockReadOnly

Open in new window



Thank you.
0
Comment
Question by:meniyk
  • 5
  • 3
  • 2
10 Comments
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39247641
Access requires parentheses within the join structures that the vast majority of databases do not require. This is what your current query looks like re-formatted:
SELECT TPJ_WO.CUSTOMERPONO
	, TPJ_SI.SHIPMENTNO
	, TPJ_SDETAILS.ITEMCODE
	, TCM_MASTER.ITEMNAME
	, TPJ_WO.WORKORDERNO
	, TPJ_WO.ITEMNAME
	, TPJ_WO.TARGETPOWER
	, TPJ_SDETAILS.SHIPMENTQUANTITY
	, TCM_FGMASTER.SHIPPINGTYPE
	, TPJ_SI.SHIPMENTDATE
FROM (
	(
		(
			TPJ_SI INNER JOIN TPJ_SDETAILS ON TPJ_SI.SHIPMENTNO = TPJ_SDETAILS.SHIPMENTNO
			) INNER JOIN TPJ_WO ON TPJ_SDETAILS.LOTNO = TPJ_WO.WORKORDERNO
		) INNER JOIN TCM_MASTER ON TPJ_SDETAILS.ITEMCODE = TCM_MASTER.ITEMCODE
	)
INNER JOIN TCM_FGMASTER ON TPJ_SDETAILS.ITEMCODE = TCM_FGMASTER.FINALPRODUCTCOD;
 

Open in new window

All those parentheses after the word FROM are not required in Oracle (or mssql) and would look like this once they are removed:
SELECT TPJ_WO.CUSTOMERPONO
	, TPJ_SI.SHIPMENTNO
	, TPJ_SDETAILS.ITEMCODE
	, TCM_MASTER.ITEMNAME
	, TPJ_WO.WORKORDERNO
	, TPJ_WO.ITEMNAME
	, TPJ_WO.TARGETPOWER
	, TPJ_SDETAILS.SHIPMENTQUANTITY
	, TCM_FGMASTER.SHIPPINGTYPE
	, TPJ_SI.SHIPMENTDATE
FROM TPJ_SI
INNER JOIN TPJ_SDETAILS ON TPJ_SI.SHIPMENTNO = TPJ_SDETAILS.SHIPMENTNO
INNER JOIN TPJ_WO ON TPJ_SDETAILS.LOTNO = TPJ_WO.WORKORDERNO
INNER JOIN TCM_MASTER ON TPJ_SDETAILS.ITEMCODE = TCM_MASTER.ITEMCODE
INNER JOIN TCM_FGMASTER ON TPJ_SDETAILS.ITEMCODE = TCM_FGMASTER.FINALPRODUCTCOD;

Open in new window

aside from that I can't see any problem in the sql (oh, those redundant parentheses would be ignored by Oracle I believe) - so that error isn't due to the sql itself.
0
 
LVL 10

Expert Comment

by:adriankohws
ID: 39247981
Check your reference. There might be a conflict. Nothing wrong with your coding.

If something like below both exist in your reference, you would have problem.

Reference: Microsoft DAO 3.6 Object Library
Reference: Microsoft ActiveX Data Objects 2.1 Library
0
 

Author Comment

by:meniyk
ID: 39268842
Hi PortletPaul,

Thank you for your response.

I have tried and use dthe query you have constructed. It does not work either.
It's work if i just do a simply query such as "SELECT * FROM TPJ_SDETAILS"

so, i'm not sure it this due to the limited payload in the Excel VBA String Object(i doubt) that send across to network.

I have no clues at all....

Thank you.

Yk
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:meniyk
ID: 39268845
Hi Adriankohws,

thank you for your response.
I have checked the reference, only Reference: Microsoft ActiveX Data Objects 2.1 Library  exists.

I have no clues how to resolved this issue. It is kind of hard for me to nail down where is problem. I suspect could it be the limited payload of string in Excel VBA Object or ADODB.Recordset send across network...

Thank you.
regards
YK
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39269014
curious, try this perhaps. I have put back the parentheses within the from clause (even though I believe they are redundant) but also given each table a single letter alias
SELECT W.CUSTOMERPONO, S.SHIPMENTNO, D.ITEMCODE, M.ITEMNAME, W.WORKORDERNO, W.ITEMNAME, W.TARGETPOWER, D.SHIPMENTQUANTITY, F.SHIPPINGTYPE, S.SHIPMENTDATE FROM ((((TPJ_SI S INNER JOIN TPJ_SDETAILS D ON S.SHIPMENTNO = D.SHIPMENTNO) INNER JOIN TPJ_WO W ON D.LOTNO = W.WORKORDERNO) INNER JOIN TCM_MASTER M ON D.ITEMCODE = M.ITEMCODE) INNER JOIN TCM_FGMASTER F ON D.ITEMCODE = F.FINALPRODUCTCOD);

Open in new window

This code looks like this when formatted
0
 
LVL 10

Assisted Solution

by:adriankohws
adriankohws earned 450 total points
ID: 39269388
Can you try not using joins and using condition to join the columns instead? For example,

Select A.xxx,  B.xxx, C.xxx Where A.xxx = B.xxx and C.yyy = B.yyy

Sometimes it helps.
0
 

Author Comment

by:meniyk
ID: 39270144
Hi PortletPaul,
thank you for your response.
It does not work if i join more than 2 tables onwards. I doubt the queries have problem.
I'm not sure does it due to oracle database or Excel VBA ADODB objects..
I hope i can get some pointers.

Thanks

regards
YK.
0
 

Author Comment

by:meniyk
ID: 39270148
Hi adriankohws,
thank you for your response.

it work, if i just use 2 table join and with condition of where clause.
However, when if i join more than 2 tables onwards, that's where the error msg come..
I'm getting annoyed with the "Excel VBA greeting message" with no clues what is going on...

it seem that there are some limitation as to max table allow join in single queries in VBA excel ADODB object..

it seem that pretty strange to me.. :(
Thanks

regards
YK
0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 1050 total points
ID: 39270159
you can rest assured that Oracle supports more than 2 table joins in a query.
this is absolutely not the constraint.
0
 

Author Comment

by:meniyk
ID: 39273821
Hi PortletPaul & adriankohws,

Manage to solve the issues now.. one of my table's name was wrong as a result not working properly... thank you for both of your time. and the points has rewarded accordinlgy.

Thank you!
best regards
YK
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question