• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 658
  • Last Modified:

Run database queries and update cells in excel

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
bond7
Asked:
bond7
  • 6
  • 4
  • 3
  • +1
5 Solutions
 
snailcatCommented:
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
 
bond7Author Commented:
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
 
snailcatCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bond7Author Commented:
I am linking to oracle database.
I am trying to know if  there is any simple way besides visual basic
0
 
nike_golfCommented:
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
 
NorieData ProcessorCommented:
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
 
bond7Author Commented:
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
 
NorieData ProcessorCommented:
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
 
nike_golfCommented:
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
 
bond7Author Commented:
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
 
nike_golfCommented:
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
 
bond7Author Commented:
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
 
NorieData ProcessorCommented:
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
 
nike_golfCommented:
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
 
bond7Author Commented:
Hello,

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


Best
bond7
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now