SQL ODBC MSQuery in EXCEL

M

mcarter

I have an excel spreadsheet and want to import data from ODBC oracle table.
I had to write the SQL code because the query could not be shown
graphically...
and it does work successfully. The problem is that I want to include
criteria in the WHERE clause for BRICKDATE, but cannot get it to work...

SELECT AC_WC_DEMOG_CRSTAB.BRICKDATE, AC_WC_DEMOG_CRSTAB.STATE,
Sum(AC_WC_DEMOG_CRSTAB."DEC1-3_RECORD_COUNT") AS "DEC1-3_RECORD_COUNT
FROM (AC_WC_DEMOG_CRSTAB)
WHERE (AC_WC_DEMOG_CRSTAB.STATE='NY')
GROUP BY AC_WC_DEMOG_CRSTAB.BRICKDATE, AC_WC_DEMOG_CRSTAB.STATE

I have tried this code but does not work...
WHERE (AC_WC_DEMOG_CRSTAB.STATE='NY') AND
(AC_WC_DEMOG_CRSTAB.BRICKDATE='2008-06-01 00:00:00'))

the date that is used is the actual date in the field that was copy/pasted in.
I need the SQL code that will work in MSQuery from exel to ODBC table.
Thanks
 
J

joel

I got the SQL below to work. You just had an extra closing parethesis. I
didn't understand what you where doing with the sum since you had the
following :"DEC1-3_RECORD_COUNT" . Is this a column in the Table? I put a
very simple query into excel and then used the Query editor tool on the VBA
worksheet to add additional parmeters until I got it to work. the SQL editor
give some good debug message to help isolate the problems. In excel 2003 all
you have to do is select a cell in the query response and then go to menu

Data - Import External Data - Edit Query. the query ediitor has a SQL
button that allows editing the SQL statements.

SELECT AC_WC_DEMOG_CRSTAB.STATE, AC_WC_DEMOG_CRSTAB.BRICKDATE
FROM `C:\Documents and Settings\Joel\My Documents\db1`.AC_WC_DEMOG_CRSTAB
AC_WC_DEMOG_CRSTAB
WHERE (AC_WC_DEMOG_CRSTAB.STATE='NY') AND
(AC_WC_DEMOG_CRSTAB.BRICKDATE='2008-06-01 00:00:00')
GROUP BY AC_WC_DEMOG_CRSTAB.STATE, AC_WC_DEMOG_CRSTAB.BRICKDATE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top