+ Reply to Thread
Results 1 to 7 of 7

Microsoft Query to pull external data?

  1. #1
    Forum Contributor
    Join Date
    03-12-2004
    Posts
    147

    Microsoft Query to pull external data?

    Does anyone know of a site that details the SQL syntax that can be used with Microsoft Query?

    Seems to be more limited than the SQL I am used to in Oracle. I am using ODBC to bring data from an Oracle database and the queries I usually run don't always work with MS Query. For example here is a SQL statement that gives me an error:

    select
    to_char(trunc(bh.modify_tstamp), 'YYYY') as year,
    to_char(trunc(bh.modify_tstamp), 'MM') as month,
    to_char(trunc(bh.modify_tstamp), 'WW') as week,
    to_char(trunc(bh.modify_tstamp), 'MM/DD/YYYY') as day,
    c.cust_id,
    sum(bh.tot_weight)
    from customer_grid c, book_hdr bh, addresses a
    where bh.cust_id = c.cust_id
    and bh.ADDR_ID = a.ADDR_ID
    and trunc(bh.modify_tstamp) between to_date('11/01/2006', 'MM/DD/YYYY') and to_date('04/15/2007', 'MM/DD/YYYY')
    and c.cust_id not in ('87466', '82364', '125465')
    and c.company_no <> '18'
    group by to_char(trunc(bh.modify_tstamp), 'YYYY'),
    to_char(trunc(bh.modify_tstamp), 'MM'),
    to_char(trunc(bh.modify_tstamp), 'WW'),
    to_char(trunc(bh.modify_tstamp), 'MM/DD/YYYY'),
    c.cust_id,

    I get the error "From keyword not where expected".

    Not sure if the following are the problem:
    -Using the <> for "not equal to"?
    -The date formats perhaps (WW, MM/DD/YYY, MM, etc)
    -Something with the group by statement?

    Any help is appreciated.

  2. #2
    Registered User
    Join Date
    02-09-2005
    Posts
    63
    I've done a lot of Oracle data access via MS Access & VBA recently and found the various syntax very fussy. Have had to put ( ) in several place that I did not expect.

    It's not clear from your post where the SQL is being executed.

    HTH

    ****

  3. #3
    Forum Contributor
    Join Date
    03-12-2004
    Posts
    147
    I went to "Import External Data" > "New Database Query" Then chose oracle as the Data Source.

    I exited from the Query Wizard and instead opened up my own SQL window in MS Query. I then copied a query that I run through Oracle and paste it in the window. I try to run it in there, with the purpose of sending it back to Excel. This works for some queries, but my more complex ones I get random errors that I have to debug with no direction on the problem

    I did some debugging and realized that MS Query doesn't like me renaming columns (i.e. cant say 'SELECT ORDER_DATA as Orders,). Also learned that I can't keep the comments in. That helped.

    Was still hoping to find a good resource that explains the syntax that does and does not work. I looked on Google for awhile and couldn't find a thing, figured I would try the forums.

    Thanks

  4. #4
    Registered User
    Join Date
    03-31-2006
    MS-Off Ver
    Excel 2003
    Posts
    76
    There is much query with MS Query for me too.
    The 'as name' expression does not work when I connect to
    dbf-files. That's true.
    As to Oracle, I know o good way to solve this in MS SQLServer.
    You can use stored procedures and views.

  5. #5
    Registered User
    Join Date
    05-11-2007
    Posts
    2

    Cool

    I cannot answer your question about why the error appears, but I have found on some on my MS Query embedded links, that the error message doesn't appear if I don't name the columns within the query (the "as ..." part).

    By taking this out, my queries have generally worked ok. If necessary, I just execute a macro to change the column headings on completion.

    If anyone can suggest why this occurs, I would be interested.

  6. #6
    Registered User
    Join Date
    03-31-2006
    MS-Off Ver
    Excel 2003
    Posts
    76
    Try as 'Year', as 'Month' and so on.

  7. #7
    Forum Contributor
    Join Date
    03-12-2004
    Posts
    147
    Thanks for the follow-up. I wound up getting more reliant on Views, something I hadn't previously used very often.

    I will try the quotes technique though, thanks

+ 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