VB6 - Query from Oracle in apprilication issue

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

LVL 11
Wilder1626Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
Wilder1626Author Commented:
You are right.

Thanks a lot. It's working now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.