Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel - sql to oracle database

Posted on 2013-06-14
10
Medium Priority
?
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

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.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

721 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