Вы находитесь на странице: 1из 6

Article by Mark Boyd

www.simpleit.tumblr.com

Excel and SQL: Living in harmony


M ost all of t he inf ormat ion in this below writ ing piec e is inf ormat ion dis s eminat ed f rom www. s ans . org and its af f iliat es. M y ex perienc e is in t he M anaged Serv ic es Prov ider s ect or , more s pec if ic ally, t he Educ at ion v ert ic al

Excel and SQL: Creating a live snapshot of your information systems. Do you understand data, information and knowledge? I am here to show you how to use all three to make good business decisions, to stay informed, to stay one step ahead of your competition. This article assumes you have some sort of central data collection system. The point of this article is to show you how to turn all your queries into one big pool of information in one worksheet in Excel. If you arent inclined to read this whole article, consider attempting this all without screenshots. 1. 2. 3. 4. 5. 6. 7. 8. Open Excel Create a data connection to your database Edit the data connection > Connection Properties > Command type > SQL Enter your SQL query there Edit the data connection again this time click ADD Do the same thing, give it a different name, and different SQL query Go to a blank Excel Spread sheet > Existing Connections > Choose data location Repeat the process with all your data connections you now have a dashboard.

From there, proceed to filter data, extrapolate data as you please. Some quick background information: Have you ever heard of a product called Kaseya? Kaseya is an I.T automation tool used for remotely monitoring and administering customer networks. It is an incredibly powerful product not without its limitations. Trawl through their user community here, and you will find people are screaming for better reporting. Kaseya has told us at the time of writing they are reworking their reporting system, but why wait? DIY is the way to go. So, DIY, the old Do it yourself. I guess it should be easy? Everyone should be doing it right? Wrong. It is easy, but it is daunting. I have for you a quick and largely useless anecdote. I recall learning about how the founder of Ikea came across his fortune. It wasnt just that he was the king of the flat pack box. He was the king of the store layout. He was a genius analytical business man. It has been said by many a consumer that they go into an Ikea store wanting a chair, they walk out with a fruit bowl, a knife set, a couch, a fridge, then a chair. This is not by accident, the stores are set out in such a way that to arrive at your intended product; you pass other things you never intended to buy. I cant remember the exact figure, but it was something like when you enter an Ikea store to buy one thing you end up buying 60 percent more than you originally intended. The concept is the gruen transfer.

Thursday, 23 June 2011

Page 1

Article by Mark Boyd

www.simpleit.tumblr.com

Bringing it back to your thirst for knowledge, you desire one thing, a report on your customers general wellbeing, but, like being in an Ikea store, you have a lot of stuff in front of you, but you dont know what you need, and heck, when you do have what you need, do you know how to use it? Alright, so loose connections on two entirely different concepts aside. Lets start looking at what we are trying to achieve. This article will explain how to connect to an SQL database in Excel, then some cool tips and tricks on filtering that data into information, to gain useful knowledge. Things you will need:

Microsoft Excel

MS Query

or

SQL Server Management Studio

Alright, the best way to approach this is getting one bit of data into Microsoft Excel from SQL I am also assuming you know how to write SQL queries, and how to use MS Query or SQL Server Management Studio to test your queries, I will only be covering Excel in this document. Lets get started. Open Excel > Move to the Data tab > From Other Sources > From SQL Server

I am going to assume you know how to connect to your database, its pretty self-explanatory, and Google is your friend. Ask around the various SQL forums if you get stuck.

Thursday, 23 June 2011

Page 2

Article by Mark Boyd

www.simpleit.tumblr.com

You made a data connection, everything looks sweet, but now what? Your connection is successful, but you have no data in your spread sheet? Oh how I hate I.T I hear you saying. Dont say that, all is not lost, there is still hope. You have done the hard part. Lets look at some screen shots below

What did I just see? What does it all mean? What on earth am I doing here? 1. 2. 3. 4. 5. 6. Data > Connections > Click it Look at your connection, It should be there it should read <servername><databasename> Click Properties Change command type to SQL this is of CRITICAL IMPORTANCE Enter your conventional regular SQL > Click OK Repeat step 1. But this time, click ADD, repeat the process, use a different SQL Query

Note: When I make a new connection, I name generally name it after the table or view from which I am pulling the data. It keeps things consistent. You can have as many data connections as you want, but remember, everywhere a data connection exists in Excel, every Refresh All will run every SQL query in every connection you have made, this can take a while, and the size of your final Excel spread sheet could become unwieldy.

Thursday, 23 June 2011

Page 3

Article by Mark Boyd

www.simpleit.tumblr.com

What should I see now? Well, if your SQL was correct you should start seeing data in your worksheet

What? How? I dont get it. When you run that query, it populates the current worksheet with what it returns. Here is a sample SQL query that would get this type of data.
select groupName, machname, DriveLetter, TotalSpace, UsedSpace, FreeSpace, VolumeName, FormatType from ksubscribers.dbo.vCurrDiskInfo where DriveLetter <> 'A' and DriveLetter <> 'D' and DriveType <> 'CDROM'and groupName not like '%sample' and groupName not like '%unnamed' and groupName not like '%othersample'and groupName not like '%lastsample'

order by machName asc

Get it? Well you should, if you dont, Google how Excel and SQL works together. I hear a lot of you want to know how to use Excel as a dashboard. You are 90% of the way there. Lets go back a step; you created multiple connections didnt you? You did what I said, and made 2? 3? 5? 20? Data connections? And I bet you wondered why? I bet you said: Hey Mark, you said make multiple data connections, but I can only use one at a time, that means I dont have a dashboard, I just have the ability to get data quickly, thats not information, let alone knowledge, it is just datayou used to be cool man, you let me down Well hold up a second soldier, dont overstep your rank, I am the one telling the story here, and I am telling you this. Multiple data connections mean multiple bits of data on one Dashboard like screen!

Please turn over the page, or scroll down, whichever one suits you. Thursday, 23 June 2011 Page 4

Article by Mark Boyd

www.simpleit.tumblr.com

So you have multiple data connections, I will reiterate it with this screen below.

Now what you want to do is bring all that data into the one spread sheet, the trick? See below.

Lets look at the highlights and numbers. 1. 2. 3. 4. 5. Existing connections Click it. Highlight your Connection Click Open Here is your data import Tell your Data where to go.

Oh no, I ran out of space on this page, so I will fill it with another story. There is a theory that talks about conventional wisdom and how it is not always wise to follow it. In American gridiron, the coaches get paid a lot of make seemingly spontaneous but wise choices. Their choices can win or lose a game. There was a game where the favourites were tipped big to win, their coach made a choice to kick field goals on 2 occasions in the game. One field goal was converted, the other missed. This prompted a study into risk and reward in American gridiron. It was discovered that from the distance the kicks were taken the abovementioned game, there was a 50 percent chance of

Thursday, 23 June 2011

Page 5

Article by Mark Boyd

www.simpleit.tumblr.com

conversion, for a 3 point score. If the team had gone for a touch down from the same position, they had a 46 percent chance of conversion for double the reward. The conventional wisdom prior to this held that a field kick should always be taken from this position, however, had the team gone for a touchdown both times, chances are they would have succeeded on at least one occasion, with no less a score than what they ended up with from the two field goals. Interesting isnt it? Conventional wisdom is not always correct, just because everyone says it is. And being risk averse requires a full understanding of the data you have in front of you. Anyway, back to it. Given all of the data connections, and pulling them into one worksheet, you should now see something similar to this screen shot, and if it is anything if your requests are anything to go by, this is exactly what you are wanting to see.

I really do hope that you are all across how to create data connections; I hope that there is enough information and tips here to get you creating multiple data connections in the one Excel document. If you can make multiple connections in the one spread sheet, then bring them into the one sheet, you have done it, you have gotten data, turned it into information, and you are on your way to knowledge. For the Kaseyans out there, we have blown customers away with these types of dashboards. The above is just a sample; I have 100 queries doing all sorts of different things. When customers visit, they see on one big 50 screen with all these metrics and think These guys are serious business, is there anything they cant see live? My MSP is an Australian company, Australia is a large country, we have customers many thousands of kilometres away, and Kaseya allows us to monitor their systems from anywhere in world. Kaseya is only a tool however, albeit a powerful one. This dashboard gives us that cutting edge insight into what is happening live on our customer networks. I implore you to give it a shot.

Thursday, 23 June 2011

Page 6

Вам также может понравиться