Solved

Run database queries and update cells in excel

Posted on 2010-11-13
15
616 Views
Last Modified: 2013-11-27
Hello,

I need to Run database queries and update cells in excel.
Is there any option to do in excel ,please give any indicators.

Best
bond7
0
Comment
Question by:bond7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 12

Expert Comment

by:snailcat
ID: 34130019
If you want to import whole tables from a database into excel then you can go to the data tab in Excel and use a connection to an Access database or another type of database using an ODBC connection.

If you need to query the database then you can connect to the database and include the query in your code using  visual basic to define the connection database and then the query as well as where you want the results to go in your excel worksheet.

see http://www.dicks-clicks.com/excel/ExternalData3.htm for a discussion and example.
0
 

Author Comment

by:bond7
ID: 34130032
Thanks snail cat,

If I need to run a simple query like "select systedate from dual" into a database and put the value in a cel of excel , do I need a Visual basic or is there any other simpler way ?

Best
bond77
0
 
LVL 12

Accepted Solution

by:
snailcat earned 100 total points
ID: 34130041
You cannot easily run a query to an external database easily.

The alternative would be to link to the entire 'dual' table in your database using the method I mentioned above (data tab>external data) and make that table a separate worksheet in your Excel workbook and then you can reference the systedate in that worksheet.

Not sure if any other experts have an alternate way that I am not thinking of.

What type of database are you linking to?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bond7
ID: 34130063
I am linking to oracle database.
I am trying to know if  there is any simple way besides visual basic
0
 
LVL 13

Assisted Solution

by:nike_golf
nike_golf earned 300 total points
ID: 34130545
You could use the native tools from Excel, mainly MSQUERY, instead of VBA.

http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/

http://office.microsoft.com/en-us/excel-help/use-microsoft-query-to-retrieve-external-data-HA010099664.aspx

Keep in mind it is very basic and if you get too complex with your query's you'll end up using VBA.

NG,
0
 
LVL 34

Expert Comment

by:Norie
ID: 34130825
You could create a connection to the Oracle database using ADO and use it to run queries.

You should be able to return single values but I'm actually wondering why you would need a query to do something like that.

What sort of queries do you want to run in the database?
0
 

Author Comment

by:bond7
ID: 34130935
I need to take count of rows from a group of tables at intervals of time.
Could you please elaborate on teh ADO option in excel.

Best
Bond7
0
 
LVL 34

Assisted Solution

by:Norie
Norie earned 100 total points
ID: 34131078
Well ADO isn't really an Excel thing, it's a standard method of connecting to a database.

I've never done it myself with Oracle but I believe it's possible, though perhaps a bit more complicated than other databases.

Have a look here  http://www.freevbcode.com/ShowCode.Asp?ID=3170.

You could also try using the macro recorder and trying Data>Get external data...New database query.

Both methods would require that you have drivers you can use for Oracle databases.
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 34131774
Also take a look at this past question with regard to ADO and ORACLE, just change your SQL to your needs:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21751278.html

SELECT COUNT(*) FROM YOURTABLE

NG,
0
 

Author Comment

by:bond7
ID: 34133614
Hello,

I tried this approach, first it gave error for data source not found and no default driver found.
Then i changed driver to Oracle in OraDb10g_home1, now it is error specified driver could not be loaded due to system error 998 (Oracle in OraDb10g_home1)

I am suspecting this is due to drivers not found in my system.
I am using excel 2007. oracle client on my laptop is ora10g, destination oracle server = 8.1.7.4

Please suggest.
0
 
LVL 13

Assisted Solution

by:nike_golf
nike_golf earned 300 total points
ID: 34135228
What approach did you try?

Yes, you will need the ORACLE ODBC driver loaded on your system.

Did you create the DSN for connecting to ORACLE?

Check these for suggestions on your error:

http://forums.oracle.com/forums/message.jspa?messageID=1525737#1525737
http://forums.oracle.com/forums/thread.jspa?threadID=433688

NG,
0
 

Author Comment

by:bond7
ID: 34136222
Hello,

Approach is
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21751278.html.

Two drivers were tried
a) Microsoft driver for oracle :- data source not found and no default driver found
b) Oracle in OraDb10g_home1 :- specified driver could not be loaded due to system error 998 (Oracle in OraDb10g_home1)

Aftre failing to get through , I tried installing Microsoft driver from microsoft.com but no change in error.

I tried creating dsn names but the errors were similar.
My summary so far:-
I do not have Microsoft driver for oracle
My Oracle in OraDb10g_home1 is having some issues, either permission issue or some other.

Looking at http://forums.oracle.com/forums/thread.jspa?threadID=433688 , I will check path again.

Any ideas will be great.





0
 
LVL 34

Expert Comment

by:Norie
ID: 34136594
The only thing I can say is what you seem to already know - you've not got the right drivers.

Have you tried on any other computer?
0
 
LVL 13

Assisted Solution

by:nike_golf
nike_golf earned 300 total points
ID: 34138394
Seems like an ORACLE installation issue to me.

Can you test the conenction through the ODBC connections in Adminstrative Tools and see if you can connect?
Are you using any other application to connect to ORACLE?

Might be a permissions issue or a system path issue??

Quote from (http://forums.oracle.com/forums/thread.jspa?threadID=191053&start=0&tstart=0)

"I had the same issue and I checked the environment variable for the PATH. It turns out the the path was all lower case "c:\orant\bin\" and the actual install directory was "C:\Orant\BIN". I modified the PATH variable to reflect the "C:\Orant\BIN" and that fixed my problem"

These are the 1st 2 items in my PATH:

C:\app\product\11.1.0\client_1\bin;C:\oracle\product\10.2.0\bin;

NG,
0
 

Author Comment

by:bond7
ID: 34144995
Hello,

I agree permissions issue or a system path issue, i will check and inform tomorrow.


Best
bond7
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 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