• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel - SQL Query

rkarunmozhi

New Member
Hi:


I established an ODBC connection to SQL database and able to connect from excel 2007. My requirement is to query for few columns from mutiple columns for set of servers


With the Query tool it is time consuming. Is it possible to have a macro or script which will get servername and reslut the needed values from the neeeded columns


Ex:

Enter servername(s): serverA

serverB


Result


ServerName Domain ContactGroup OperatingSystem ProductionType

serverA a.com SA team Unix Dev

serverB b.com DBA team DBA test
 
Hi, rkarunmozhi!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about your question...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


I'd recommend you to begin reading this:

http://chandoo.org/forums/topic/programmers-guide-for-adodb-objects

http://chandoo.org/wp/2012/04/02/using-excel-as-your-database/

http://chandoo.org/forums/topic/issues-with-using-excel-as-a-database-sample-file

http://chandoo.org/wp/2008/09/22/sql-insert-update-statements-from-csv-files/


Regards!
 
Thanks for the reply.


Already I tried the search , the issue is the Database is huge wo I don't want get all the data and dump it excel and query it..


Also I am new to sql and macro
 
Hi, rkarunmozhi!


Good for you if you have read all the links posted.


And as you did, you should have noticed that following the related links:

http://www.w3schools.com/ado/ado_connect.asp

http://www.w3schools.com/ado/ado_recordset.asp

http://www.w3schools.com/ado/ado_query.asp

http://www.w3schools.com/ado/ado_getstring.asp


... you have all the components needed to setup a connection to any server, which could be extracted from a list thru a For...Next loop that's what you were asking for.


Now if you're looking for an out-of-the-shelf ready-to-use solution I'm afraid that there's none available as far as I know. So if you're new to SQL and macro, I'd dare to suggest you to start by copying the code for each part (connection, open db, recordset, query) and build a Sub procedure that retrieves the data for one server in particular.


Once you've done that I'd be glad to help you build the caller macro that merges your server list with the procedure macro you've made in the prior pass.


Regards!
 
Back
Top