Archive of posts filed under the SQL Server category.

Getting Started with PowerPivot

Last week I took a stab at creating my first PowerPivot spreadsheet, and I wanted to document the steps.  Maybe this post will help someone, but it will help me remember, that is for sure!

Before you get started, you will need to download all the software required.  Here is my list:

Of course, you will need and instance of SQL Server 2008.  You can just use Express edition if you do not have one installed.

Now that I have everything installed and configured, I can start with PowerPivot.  One note – look for Hand shaped cursor in the screens below.s

Step 1 – Start up Excel 2010 and look for PowerPivot menu, then click on PowerPivot Window to launch pivot.

image

Step 2 – click on From Database in the window, then Select from SQL Server

image

Step 3 – Fill in SQL Server details.  I am choosing to use Data Warehouse DB.  Click Next when done.  On the next screen select an option to Select for a list of tables and views.

image

Step 4 – Select dimension tables and fact table to analyze.  Here is my list in alphabetical order

  • DimCustomer
  • DimDate
  • DimProductCategory
  • DimSalesTerritory
  • FactInternetSales

You can select any tables you like of course.  Wait while data is imported into PowerPivot, then click Close.  PowerPivot window will now have five tabs with data and columns directly imported from the database.  Here is what it looks like.

image

Now click on PivotTable menu and select  Chart and Table – Vertical option.  We will simply create a chart and an analysis table to go with it.  Click on New Worksheet when prompted.  This step will return you back to main Excel window.  You will see chart, table and on the left hand side Gemini task pane – listing of imported data.  Gemini used to be Microsoft code name for this product/functionality.

image

Step 5 – Building a chart.  We are going to analyze sales based on customer marital status by linking it to sales amount.  Click on the chart first, then in Gemini pane expand DimCustomer table and select MaritalStatus.  Then, expand FactInternetSales and select SalesAmount.  PowerPivot will guess what we are trying to do and MaritalStatus as Axis field and Sum(SalesAmount) as Values.  Here is what it looks like:

image

 

Step 6 – building table with filters. 

Click on table first, then check the following tables/fields in Gemini pane:

  • DimCustomer – MaritalStatus and Gender
  • DimDte – CalendarYear
  • DimProductCategory – EnglishProductCategoryName
  • DimSalesTerritory – SalesTerritoryCountry
  • FactInternetSales – SalesAmount

At this point your bottom of Gemini pane should look like this:

image

if you have anything else in Values, click on that item and select “Move to Row labels”.  What you will see also is that your have a report built for you in table area that uses all the analysis points.  You could leave it as is, but I will do more.

 

Step 7 Now I can analyze the data by “slicing it”.  To do this we will create two groups of slices – horizontal and vertical.  We will split our analysis categories as follows:

  • Horizontal Slices: Marital Status and Gender
  • Vertical Slices –English Product Category and Calendar Year.

I will leave Sales Territory country as a column in my table. To perform this I will click on each of my slices and select “Move to Slices Horizontal (or Vertical) as appropriate.  Then I click on each slice and choose Move Up or down until my pane looks like this:

image

Now here is what my table looks:

image

I will go ahead and move things around to make spreadsheet look better:

image

 

Step 8 – Use slices for analysis.  This process is super simple – just click on a desired slice(s) to enact filter on rows of a table.

image

To clear the filter just click on a funnel picture with x across it:

image

As you do so, you will see the chart and table both updating with your filter values.  One thing I did notice at the end – Catergory is lon linked to internet sales, so category filter has no effect on data.  If you see similar behavior, your data has the same issue.  You can always manually build relationships in PowerPivot by click on Table tab in pivot and choosing Manage Relationships menu:

image

 

As you can see, using PowerPivot is extremely easy and the results are very powerful.  You can save your spreadsheet, open it later and refresh the data by clicking on a filter!  You also have an option to show or hide Gemini panels in Excel under PowerPivot menu.  In the same menu you also have an option to show or hide Gemini panels.

Thanks.

Silverlight 4 + COM + SQL Server = Cool!

Today is the day to talk about COM possibilities in Silverlight 4.  One would question the titles of my post.  COM and Cool in the same sentence?  Let me proof this title to you.

First, let me take a closer look at COM.  In order to access COM, you must install Silverlight application on a local machine.  The access to COM is not enabled when a Silverlight application is run in the browser.  So, first of all you have to enable this by checking “Enable running application out of browser” checkbox in project properties.  Second of all, you have to check “Require elevated trust…” checkbox in “Out-of-browser settings” area in project properties.  Now, you are ready to install you application and test COM support.  How about Word automation:

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
var doc = word.Documents.Add();
var paragraph = doc.Paragraphs.Add();
paragraph.Range.Text = "Some text";

Now, let’s talk about database access.  Parts of System.Data.SqlClient namespace are not exposed to COM by default.  So, to enable database access we must write an assembly that is exposed to COM that wraps database access.  To do so, check the property “Register for COM Interop” in project properties for the .NET (NOT Silverlight) based project that will fire off database queries for us.  Once the assembly is built, I can just use RegAsm to register my DLL with COM on a machine.  Of course, this would be a prerequisite to use Silverlight application for local data access.  The other prerequisite is to have .NET Runtime installed on that machine as well.  I could write an install project of course to make this process easier.

The next step is to write a Silverlight assembly that would use COM Interop similar to the one above for Word to talk to my database access .NET based assembly.

dynamic sqlDB = ComAutomationFactory.CreateObject("COMSQLClient.COMSqlDatabase");

Now the most exciting part.  I created and published the project on CodePlex that does exactly what I just talked about.  Check out the project and let me know what you think.  You can download the source code and look into the implementation details.  Here is the link to it:

http://silverlight4sqllib.codeplex.com/

Thanks.

Talk at GGMUG

As always I had fun presenting at Gwinnett Georgia Microsoft Users Group on Thursday.  The subject of my talk was “Getting started with SQL Azure”.  I documented all the steps in this blog post.  There are also useful links that I mentioned in this post to help you get started.

There are many advantages to use SQL Azure.  Number of reason is probably the fact that one can eliminate the need to house expensive hardware and software on premises.  As long as you are fine with living with certain limitations of SQL Azure compared to SQL Server 2008, you can take advantage of this great technology.  The primary limitation is probably the size of the database.  You cannot have a database bigger than 10 GB.

Feel free to ask any questions on the topic.

Windows Azure Application

This is purely a bragging post :-)

I just deployed a test application to the cloud (Microsoft Azure): http://rolodex.cloudapp.net/

Here is the technology stack for it:

  1. Windows Azure
  2. SQL Azure
  3. CSLA 3.8.1
  4. Silverlight
  5. Entity Framework
  6. WCF
  7. Prism (Composite Application Guidance)
  8. Silverlight Toolkit

I promise to write a blog entry in the near future, the steps one has to follow through to create an Azure application.

SQL Saturday #25

I spoke yesterday at SQL Saturday event in Gainesville, GA.  My topic was CLR Integration in SQL Server. 

CLR stands for Common Language Runtime or .NET Framework.  This SQL Server 2005 or higher feature allows developers to write .NET assemblies and deploy them in SQL Sever.  You can implement scalar and table-values functions, stored procedures, triggers, user defined types and aggregates.

In my talk I spoke of features that I worked or had a need for.  Those included interacting with OS, such as file access or registry access.  I also talked about implementing fuzzy matching logic, creating custom bitmaps and utilizing them in SSRS reports.

You can download the sides and sample project here.

Thank you.

SQL Saturday Presentation

My talk at SQL Saturday just ended. My topic was CLR integration – Integrating CLR assemblies to support custom image creation and encompassing complex business logic in SQL server/SSRS.  I posted all the code and slides here

As always it was a pleasure to talk in front of my fellow developers.