Solved

Run database queries and update cells in excel

Posted on 2010-11-13
15
573 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
  • 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
 

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 33

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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 33

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 33

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

757 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now