tim laqua dot com Thoughts and Code from Tim Laqua

27Feb/120

Slowly Changing Dimensions with MD5 Hashes in SSIS

sqlserver_sql_server_2008_FI

We recently moved away from the 3rd party Checksum component (and all 3rd party components) in SSIS and I wanted to share the pattern we settled on for maintaining our Type 1 Slowly Changing Dimensions (SCDs). There are two things we wanted to address with our new pattern. First, our previous implementation wasn't performing as well as we needed it to or generating reliable checksums. The second was that we wanted to get away from dependencies on custom assemblies in general. To illustrate the pattern, we're going to build a SCD package off the Adventure Works DW DimCustomer table and skip over the actual source of the business keys and attributes by selecting directly from the completed dimension for now.

First, we assume that our dimension already exists (and we were using some other checksum or MERGE to maintain it). We have to add a column to store the MD5 hash:

ALTER TABLE dbo.DimCustomer ADD
	MD5 VARCHAR(34) NOT NULL DEFAULT ''

Second, we need a staging table to store updated/changed rows. Script out the current dimension as a CREATE, remove all unneeded constraints and indexes, and create a staging table as a heap:

CREATE TABLE [dbo].[Staging_DimCustomer_UpdatedRows](
	[CustomerKey] [INT] NOT NULL,
	[GeographyKey] [INT] NULL,
	[CustomerAlternateKey] [NVARCHAR](15) NOT NULL,
	[Title] [NVARCHAR](8) NULL,
	[FirstName] [NVARCHAR](50) NULL,
	[MiddleName] [NVARCHAR](50) NULL,
	[LastName] [NVARCHAR](50) NULL,
	[NameStyle] [BIT] NULL,
	[BirthDate] [DATETIME] NULL,
	[MaritalStatus] [NCHAR](1) NULL,
	[Suffix] [NVARCHAR](10) NULL,
	[Gender] [NVARCHAR](1) NULL,
	[EmailAddress] [NVARCHAR](50) NULL,
	[YearlyIncome] [MONEY] NULL,
	[TotalChildren] [TINYINT] NULL,
	[NumberChildrenAtHome] [TINYINT] NULL,
	[EnglishEducation] [NVARCHAR](40) NULL,
	[SpanishEducation] [NVARCHAR](40) NULL,
	[FrenchEducation] [NVARCHAR](40) NULL,
	[EnglishOccupation] [NVARCHAR](100) NULL,
	[SpanishOccupation] [NVARCHAR](100) NULL,
	[FrenchOccupation] [NVARCHAR](100) NULL,
	[HouseOwnerFlag] [NCHAR](1) NULL,
	[NumberCarsOwned] [TINYINT] NULL,
	[AddressLine1] [NVARCHAR](120) NULL,
	[AddressLine2] [NVARCHAR](120) NULL,
	[Phone] [NVARCHAR](20) NULL,
	[DateFirstPurchase] [DATETIME] NULL,
	[CommuteDistance] [NVARCHAR](15) NULL,
	[MD5] [VARCHAR](34) NOT NULL)

Now in to SSIS - We will be building:

  1. Execute SQL Task to Truncate our Staging table(s)
  2. Data Flow Task to Insert new rows and Stage updated rows
  1. OLE DB Source to retrieve our source data
  2. Script Component to Generate Row Numbers
  3. Conditional Split to Evenly Distribute Rows
  4. Script Component to Generate MD5 Hashes
  5. Union All to Squish it all back together
  6. Lookup to get the existing MD5 Hash (if it exists)
  7. Conditional Split to separate Unchanged and Changed rows
  8. RowCount Transformation
  9. OLE DB Destination for Changed rows
  10. OLE DB Destination for New rows
  • Execute SQL Task to Update changed rows
  • Completed Control Flow

    Completed Data Flow

    24Jul/111

    Troubleshooting: 1998 Jeep Grand Cherokee (ZJ) Doesn’t Start – Cranks, No Fuel, No Spark

    JeepBadge

    This has been one of the most frustrating repairs we have come across. One day the Jeep just plain refused to start anymore. We have had prolonged starting times for a while now where we will let fuel pump prime at least twice before it would start, but it would always start. Nothing really precluded the no start condition, we just turned it off one day and it didn't want to start again. The symptoms don't really point to any particular component (other than the PCM) and without some fancy tools, you'll do exactly what we did - replace the PCM... and it won't fix anything. So we took out our fancy tool, looked up some diagnostic diagrams on alldatadiy.com, and got to work.

    A few things to check for right away to see if you're having the same issue we were:

    • Check to see if the fuel pump runs during cranking - ours didn't
    • Check for spark during cranking - we didn't have any
    • Check to see if your check engine light is on (ours WASN'T)
    • Check your voltage and fuel gauges with the ignition on - ours didn't register anything
    • Check to see if your low fuel light is on - our was
    28Nov/0819

    BlackBerry Storm (9530) Error: SIM Card Rejected

    This error pops up when you lose CDMA (1XEV) connectivity in the US and the phone attempts to connect to a GSM network (you can duplicate if you force your Storm to GSM network technology) and you have a Global SIM card installed (and most of us do). The kicker is that the message "SIM Card Rejected" doesn't go away until your hard reboot - even after you've reconnected to the CDMA network.

    So, if you're not using your Global SIM (if you are, call VZW and ask for Global Support - they can activate your SIM), you can just force CDMA only on the phone, do a battery pull, and you'll never see this again. I assume some future firmware update will handle this error better by making it go away once you're back on CDMA, but for now - this is what I had to do:

    16Nov/080

    Installing ASTrace.exe in a 64-bit environment

    ASTrace.exe is part of the SQL Server Analysis Services Community Samples on CodePlex. This utility works just fine in a 32-bit environment, however some of the assemblies needed to interact with Analysis Services do not have 64-bit counterparts - thus, you have to use WOW64 to get the service to work properly on a x64 machine.

    ASTrace can be downloaded here:
    http://www.codeplex.com/SQLSrvAnalysisSrvcs/Release/ProjectReleases.aspx?ReleaseId=13572

    32-bit Installation Instructions can be found here:

    http://msdn.microsoft.com/en-us/library/bb283156(SQL.90).aspx

    And to get it to work on x64, you need to do two things differently:

    • Target x86 processors when you build the application - this way, your 64-bit OS will use WOW64 when the service runs (Project > ASTrace Properties... > Build Tab).

    • Create the following registry key and string value pointing to where you copied the ASTrace files:
      [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASTrace]
      "path"="C:\\ASTrace"
    5Nov/080

    How to add a calculated measure (calculated field) to an Excel 2007 PivotTable with a SSAS data source

    As it turns out, you can do it programatically as explained by Allan Folting here:
    Microsoft Excel: Common Questions Around Excel 2007 OLAP PivotTables:
    http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx

    And the parts that I have to keep looking up (I use my blog as a notebook for things I don't want to forget ;-) :

    Sub AddCalculatedMeasure() 
    	Dim pvt As PivotTable
    	Dim strName As String
    	Dim strFormula As String 
     
    	Set pvt = Sheet1.PivotTables("PivotTable1")
    	strName = "[Measures].[Internet Sales Amount 25 %]"
    	strFormula = "[Measures].[Internet Sales Amount]*1.25"
    	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMember 
    End Sub 
     
    Sub AddCalculatedMember() 
    	Dim pvt As PivotTable
    	Dim strName As String
    	Dim strFormula As String 
     
    	Set pvt = Sheet1.PivotTables("PivotTable1")
    	strName = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38 25 %]"
    	strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38]*1.25"
    	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedMember
    	pvt.ViewCalculatedMembers = True 
    End Sub 
     
    Sub AddNamedSet() 
    	Dim pvt As PivotTable
    	Dim strName As String
    	Dim strFormula As String
    	Dim cbf As CubeField 
     
    	Set pvt = Sheet1.PivotTables("PivotTable1")
    	strName = "[My Mountain Bikes]"
    	strFormula = "[Product].[Product Categories].[Bikes].[Mountain Bikes].children"
    	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, Type:=xlCalculatedSet
    	Set cbf = pvt.CubeFields.AddSet(Name:="[My Mountain Bikes]", Caption:="Mountain Bikes") 
    End Sub

    He also mentions that you can expose these members to Excel Services 2007 by creating the new objects and then removing the VBA code - very useful article.

    14Sep/08222

    How to replace the battery in a Polar F11 Heart Rate Monitor (HRM)

    Disclaimer: The user manual for the Polar F11 clearly states to take the HRM to a Polar dealer and have them replace the battery - taking the back off could void your warranty. If you wish to be 100% sure that you maintain the water-resistant seal and do not want to void your warranty - or risk breaking your HRM (certainly a possibility when you take it apart...), take the unit to an authorized Polar dealer and have them replace the battery.

    Step 1: Remove the back cover (4 little screws - make sure you have the right size screwdriver or you'll strip them out). Also note that the back has a water-resistant seal - keep this clean and remember that there is always a chance that the seal may be damaged if you do this yourself.
    Step 2: Remove the internal unit from the watch casing (it just pulls out).
    Step 3: Get something to pry the battery latch tab with (I used another small screwdriver)
    Step 4: Take whatever you used to pry the latch tab out with and use it to pry the battery up by placing the device (screwdriver in my case) in the notch above the latch (see picture).
    Step 5: Go to Wal-Mart and purchase a new CR2032 watch battery (you may want to do this before hand... I didn't know what battery it used so I had to take it out first) - runs about $3.50.
    Step 6: Put the battery back in and put everything back together.