Solved

VB6 - Query from Oracle in apprilication issue

Posted on 2014-02-16
3
321 Views
Last Modified: 2014-02-16
HI all

I have this below SQL that work great in Oracle.

But when i want pull the extract from my VB6 app and get the result inside my MSHFlexgrid2, i have a Compile error, syntax error.

Would you know why?

Thanks again for your help

SQL in app:
Dim oconn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strSQL As String

    strSQL = "SELECT DC, STORE_NUM, PICK_DC, RECEIVE_DC, LANE_NUM, RTRIM( " & _
             "EXTRACT( XMLAGG( XMLELEMENT( "x", RELEASE_DAY || ',' || ARRIVE_DAY " & _
             "|| ',' || RECEIVE_ARRIVE_OPEN || ',' || RECEIVE_ARRIVE_CLOSE || ',' ) " & _
             "ORDER BY RELEASE_DAY, ARRIVE_DAY, RECEIVE_ARRIVE_OPEN, RECEIVE_ARRIVE_CLOSE ), '/x/text()' ).GETSTRINGVAL(), " & _
             "','  ) X FROM (SELECT A.PICK_DC AS DC, A.STORE_NUM, C.PICK_DC, C.RECEIVE_DC, C.SHIP_DAY AS RELEASE_DAY, C.ARRIVE_DAY, " & _
             "C.RECEIVE_ARRIVE_OPEN, C.RECEIVE_ARRIVE_CLOSE, C.LANE_NUM FROM LCLRPT.DC_STORE_SETTINGS A, LCLRPT.LCL_STORE_LANE_REF B, LCLRPT.XD_LANES C " & _
             "WHERE A.DC_STORE_SETTINGS_SEQ_NUM= B.DC_STORE_SETTINGS_SEQ_NUM AND B.LANE_NUM= C.LANE_NUM AND B.LANE_GROUP=0) GROUP BY DC, " & _
             "STORE_NUM, PICK_DC, RECEIVE_DC, LANE_NUM"

    Set oconn = New ADODB.Connection
    oconn.Open "Provider=OraOLEDB.Oracle.1;Data Source=xxxxx;User Id=xxxxx;Password=xxxxx;"
    rs.CursorType = adOpenStatic
    rs.CursorLocation = adUseClient
    rs.LockType = adLockOptimistic
    rs.Open strSQL, oconn, adCmdText
    Set MSHFlexGrid2.DataSource = rs

    rs.Close
    oconn.Close
    Set rs = Nothing
    Set oconn = Nothing

Open in new window


SQL that works in Oracle Dev.
SELECT DC,
         STORE_NUM,
         PICK_DC,
         RECEIVE_DC,
         LANE_NUM,
         RTRIM(
             EXTRACT(
                 XMLAGG(
                     XMLELEMENT(
                         "x",
                            RELEASE_DAY
                         || ','
                         || ARRIVE_DAY
                         || ','
                         || RECEIVE_ARRIVE_OPEN
                         || ','
                         || RECEIVE_ARRIVE_CLOSE
                         || ','   
                     )
                     ORDER BY
                         RELEASE_DAY,
                         ARRIVE_DAY,
                         RECEIVE_ARRIVE_OPEN,
                         RECEIVE_ARRIVE_CLOSE
                 ),
                 '/x/text()'
             ).GETSTRINGVAL(),
             ','    
         )
             X
    FROM (SELECT
    A.PICK_DC AS DC,
    A.STORE_NUM,
    C.PICK_DC,
    C.RECEIVE_DC,
    C.SHIP_DAY AS RELEASE_DAY,
    C.ARRIVE_DAY,
    C.RECEIVE_ARRIVE_OPEN,
    C.RECEIVE_ARRIVE_CLOSE,
    C.LANE_NUM
FROM
    LCLRPT.DC_STORE_SETTINGS A, LCLRPT.LCL_STORE_LANE_REF B, LCLRPT.XD_LANES C
WHERE
    A.DC_STORE_SETTINGS_SEQ_NUM= B.DC_STORE_SETTINGS_SEQ_NUM
    AND B.LANE_NUM= C.LANE_NUM
    AND B.LANE_GROUP=0)
GROUP BY DC,
         STORE_NUM,
         PICK_DC,
         RECEIVE_DC,
         LANE_NUM;

Open in new window

0
Comment
Question by:Wilder1626
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39863051
first some tip: as the query has no parameters, I usually would put the query into a view (in oracle), and your application will then only have to do:
SELECT * FROM VIEW_NAME

this will solve a couple of issues, the main one being to remove all the (complex) sql stuff from the actual application code. others are that you will give the power to the dba to eventually optimize the sql (view) without having the application to be recompiled and redistributed.

let me check what the error could be, meanwhile
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39863056
now, I see the issue:

... XMLELEMENT( "x", ...

inside your string declaration would need to be:
XMLELEMENT( ""x"",

as the " is already the string delimiter (in vb), to use the " inside the string, you need to duplicate it.
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39863100
You are right.

Thanks a lot. It's working now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now