Feb 102010
 

Teradata offers the ability to build a query, and then use a QUALIFY statement that filters the resulting resultset. This is especially handy when using a ROW_NUMBER function where you are partitioning on a natural key (or whatever it may be) and you want to return only the rows where the ROW_NUMBER value is 1, for example.

In SQL Server today, this has to be done with derived tables/CTEs like so:

USE AdventureWorksDW
GO
/* Ignoring the fact that this table
   has a "Status" and an EndDate column */
;WITH CTE AS (
SELECT EmployeeKey,
       FirstName,
       LastName, 
       MiddleName,
       Title,
       ROW_NUMBER() OVER (PARTITION BY EmployeeNationalIDAlternateKey
                              ORDER BY StartDate DESC) AS ROW_NUM
  FROM dbo.DimEmployee
)
SELECT EmployeeKey,
       FirstName,
       LastName,
       MiddleName,
       Title
  FROM CTE
 WHERE row_num = 1
 ORDER BY FirstName, LastName
GO   

That’s easy enough to understand, of course, but the problem lies in the fact that you have to write a bunch of extra lines of code to accomplish this task.

Teradata has the QUALIFY option which would be represented like this:

 SELECT EmployeeKey,
        FirstName,
        LastName, 
        MiddleName,
        Title
   FROM dbo.DimEmployee
QUALIFY ROW_NUMBER() OVER (PARTITION BY EmployeeNationalIDAlternateKey
                               ORDER BY StartDate DESC) = 1

Note how much cleaner that looks. QUALIFY has many advantages, but I’ll leave that as an exercise for you to review. In the mean time, if you would like to see such an option in SQL Server, please vote on Itzik Ben-Gan‘s feature request: https://connect.microsoft.com/SQLServer/feedback/details/532474/qualify-request-for-a-new-filtering-clause

Feb 082010
 

I’m reposting a list of task/component prefix naming conventions that Jamie Thomson posted some years back for SSIS. Using a standard set of prefixes allows for easy log reading, better multi-developer support, and ease of readability.

Get the Excel document here: SSIS_Prefix_Naming.xlsx (11 KB)

Note that I have not updated this document for 2008 task/component changes, and some of the abbreviations may have been changed from Jamie’s original list of suggestions to suit the needs of my organization at the time.

Feb 032010
 

A quick tip for those that may want some better organization over the default provided by BIDS when working with SSIS packages.

You can add your own groupings to the Toolbox window by right-clicking anywhere in the toolbox, and selecting “Add Tab”.

For example, in the data flow window, I can add a new tab (or grouping) for Analysis Services Destination components.

1) Right click on the toolbox background and select “Add Tab”

Add Tab

Add Tab

2) Give it a name.

Name Tab

Name Tab

3) Drag components to the new tab.

Dragging Components

Dragging Components

4) Repeat as needed.

Repeat as needed

Repeat

The final results might look something like this:

Final Results

Final Results