+ Reply to Thread
Results 1 to 4 of 4

unable to excute query

  1. #1
    Registered User
    Join Date
    01-12-2007
    Posts
    41

    unable to excute query

    hi
    in my excels iam using the external source

    With ActiveSheet.QueryTables.Add(Connection:= _
    "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=scott;PWD=tiger;SERVER=dev;" _
    , Destination:=Range("A1"))
    .CommandText = Array( _
    "SELECT TELE.CALLING_DATE, TELE.CALLING_TIME, TELE.CALLED_NUMBER, TELE.DURATION, TELE.UNITS" & Chr(13) & "" & Chr(10)

    & "FROM SCOTT.TELE TELE" _

    -----
    but i unable excute this query

    SELECT TELE.CALLED_NUMBER, sum(TELE.DURATION) DURATION, sum(TELE.UNITS) UNITS
    FROM SCOTT.TELE TELE
    group by TELE.CALLED_NUMBER
    order by DURATION,UNITS

    error :: from caluse

  2. #2
    Registered User
    Join Date
    08-19-2007
    Posts
    40

    unable to excute query

    Hello

    Try putting a space after your FROM Statement as shown in the example below. What is happening is that it is making your statement to be FROM SCOTT.TELE TELEGROUP BY TELE.CALLED_NUMBERorder by DURATION,UNITS


    ie.,

    With ActiveSheet.QueryTables.Add(Connection:= _
    "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=scott;PWD=tiger;SERVER=dev;" _
    , Destination:=Range("A1"))
    .CommandText = Array( _
    "SELECT TELE.CALLING_DATE, TELE.CALLING_TIME, TELE.CALLED_NUMBER, TELE.DURATION, TELE.UNITS" & Chr(13) & "" & Chr(10)

    & "FROM SCOTT.TELE TELE " _

    BTW: You can use the VBA statement for Carriage Return and Line Feed. of VbCrLf which would save you using Chr(13) and Chr(10).

    Hope this helps.

    Cheers,
    Kind Regards,

    Steven Daniel
    ONTRACK SOFTWARE & TECHNOLOGY SOLUTIONS
    http://www.ontrack-software.com.au/

  3. #3
    Registered User
    Join Date
    01-12-2007
    Posts
    41

    identifier is too long

    "SELECT TELE.CALLED_NUMBER, sum(TELE.DURATION) , sum(TELE.UNITS)
    &"FROM SCOTT.TELE TELE "
    "group by TELE.CALLED_NUMBER"
    "order by DURATION,UNITS"

  4. #4
    Registered User
    Join Date
    08-19-2007
    Posts
    40
    Hello

    Try formatting your statement as follows:

    "SELECT TELE.CALLED_NUMBER, sum(TELE.DURATION) , sum(TELE.UNITS)" & VbCrLf & "FROM SCOTT.TELE TELE "
    "group by TELE.CALLED_NUMBER"
    "order by DURATION,UNITS"

    Identifier error : try assigning your SQL Statement to a variable and then using that variable in your connection

    Ie.,

    StrSQL = "SELECT TELE.CALLING_DATE, TELE.CALLING_TIME, TELE.CALLED_NUMBER, TELE.DURATION, TELE.UNITS" & VbCrLf & _
    "FROM SCOTT.TELE TELE " & _
    "GROUP BY TELE.CALLED_NUMBER " & _
    "ORDER BY DURATION, UNITS"

    With ActiveSheet.QueryTables.Add(Connection:= _
    "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=scott;PWD=tiger;SERVER=dev;" _
    , Destination:=Range("A1"))
    .CommandText = Array(strSQL)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1