A Great Day At SQL Saturday Redmond

It was a great day at SQL Saturday today. I was able to preview my Common Table Expressions Book at my Common Table Expressions presentation.  The presentation was great, the room was packed, and there were lots of great questions.

sqlsat212_web

Here is the lineup for the room that I presented in.  Just before me was Rick Morelan presenting on SQL 2012 Error handling, which was a spectacular presentation.

One presentation that I wish I had attended was the Machine Learning for Mere Mortals from Dev Nambi. Although the presentation that I went to in the same time slot was great, I wish I had been able to go to both.

image

The slides are available for download from the presentation here:  Steve Stedman CTE Presentation.

One thing that I had a hard time with during this presentation was being able to get all of the information covered in a hour.  After writing my Common Table Expressions Book I had so many things I my mind that I wanted to cover, but the time just didn’t allow for it.  I think that I will split the CTE presentation into two 1 hour sessions, first the introduction to CTEs for those who have not used CTEs in the past, and then the advanced CTEs for the really fun stuff.

Happy Birthday SQL Server 2012

It has been a year since SQL Server 2012 released.

There were some fun posts on Twitter about the SQL Server 2012 birthday or anniversary. For instance:

declare @greetings varchar(100)

SET @greetings= 'Happy Birthday @SQLServer 2012'

SELECT @greetings

and another anniversary query (which doesn’t actually run):

SELECT Happy FROM Anniversary WHERE Year = 1 AND Version = '11.0.2100.60';

1 year out since SQL 2012 released, and here are some things to note:

There is no more Business Intelligence Development Studio (BIDS) in SQL Server 2012, instead it has been replaced with the SQL Server Data Tools that uses the core of Visual Studio 2010, with the Report Builder and Report Designer built in to the new Visual Studio.

SQL Server 2012 introduced a new T-SQL object used to generate numbers, a SEQUENCE, similar to an identity column.

SQL Server 2012 introduced the IIF statement. It is very similar to the IIF statement in MS Access.

In SQL Server 2012 there is a new function called CHOOSE that takes in an offset, and a list of options.

The OFFSET and FETCH functionality was added  to achieve data paging server side in TSQL.

Other Notable features:

I hope you are able to get as much out of SQL Server 2012 as I am.  Happy Birthday to SQL Server 2012.

Over 400 downloads of the database health reports.

Today, the Database Health Reports had its 400th download.  I would like to say thank you to everyone who is using the product, and an extra thank you to those who have provided me with feedback.

Here is a history of the Database Health Report project, http://databasehealth.stevestedman.com/about.

My Goal:  I would like to provide the Database Health Reports project for free to as many people as I possibly can for as long as I can.  One day I am sure that it will require more of a support team, and more developers, but as long as I can do this for FREE with just me working on it I will continue to do that.

Download

If you haven’t tried out the Database Health Reports project you can get it from the FREE download page.

I am currently working on Beta 6. Currently Beta 5 is out in the wild and going well.

Thanks!!!

Thanks everyone for using the Database Health Reports project!

-Steve Stedman

Swag

image

Coding on the Database Health Reports project, making notes in my Quest Software notebook, with a pencil from Redgate SQL in the City, wearing my Confio t-shirt, refilling my SQLSentry plastic pint glass with a Nalgene bottle from Quest Software, storing data on my Redgate thumb drive, overwhelmed with all the swag from the last several conferences.

 

Oh and don’t forget the Redgate hot sauce with the SQL Source control license on it from a year ago.

TSQL 2012 – Generating letters with a SEQUENCE object

As shown in my previous posting on SEQUENCES, they are a user-defined object that generates a sequence of numeric values in Transact SQL 2012.  But what if you want to generate letters instead of numbers.

Here is a code example of a sequence used to generate letters (indirectly).


-- SEQUENCE
-- generating letters with a sequence.
--DROP SEQUENCE lettersSequence;
CREATE SEQUENCE lettersSequence
 AS tinyint
MINVALUE 65
 MAXVALUE 90
 CYCLE
 INCREMENT BY 1 ;

SELECT char(NEXT VALUE FOR lettersSequence) ;
SELECT char(NEXT VALUE FOR lettersSequence) ;
SELECT char(NEXT VALUE FOR lettersSequence) ;
SELECT char(NEXT VALUE FOR lettersSequence) ;
SELECT char(NEXT VALUE FOR lettersSequence) ;

Which generates the following output.

Just another cool trick with new features in sql server 2012.

 

For more info on sequences, take a look at my presentation for SQL Saturday 166 in Olympia WA.

Adventureworks2012 data to Google GeoChart Visualization

There are so many cool tools available today for data visualization.   This posting covers pulling data from the AdventureWorks2012 database running on SQL Server 2012, and then using the Google Visualization tools to display geographic data.

The final outcome will the this map.

People in the AdventureWorks2012 database.

Here is how I did it.

Step 1:

Create a query that generates totals for countries.  I wrote the following query to pull the totals by country.

SELECT cr.name, count(1)
  FROM [Person].[Address] a
 INNER JOIN [Person].[StateProvince] sp
       ON sp.StateProvinceID = a.StateProvinceID
 INNER JOIN [Person].[CountryRegion] cr
       ON cr.CountryRegionCode = sp.CountryRegionCode
 GROUP BY cr.name;

Which produced the following output.

Step 2:

Take a look at the Google code playground example at https://code.google.com/apis/ajax/playground/?type=visualization#geo_chart

Now all you need to do is replace the default list with the actual list from your query.

Step 3:

Format the query output to match the list format:

SELECT '[''' + cr.name + ''', ' + cast(count(1) as varchar(1024)) + '],'
  FROM [Person].[Address] a
 INNER JOIN [Person].[StateProvince] sp
       ON sp.StateProvinceID = a.StateProvinceID
 INNER JOIN [Person].[CountryRegion] cr
       ON cr.CountryRegionCode = sp.CountryRegionCode
 GROUP BY cr.name;

This query produces the following output.

Step 4:

Copy and paste the data from SQL Server Management Studio into the Code Playground example, like this:

Click the run code button in the Google Code Playground, and see if your code runs.  If not you will need to work out any bugs.

Step 5:

Copy the code and save it to a web page on your site.   The source code will look something like this:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/
xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<title>Google Visualization API Sample</title>
<script type=”text/javascript” src=”http://www.google.com/jsapi”></script>
<script type=”text/javascript”>
google.load(‘visualization’, ’1′, {packages: ['geochart']});

function drawVisualization() {
var data = google.visualization.arrayToDataTable([
['Country', 'Popularity'],
['Australia', 3632],
['Canada', 1688],
['France', 1851],
['Germany', 1821],
['United Kingdom', 1954],
['United States', 8668]
]);

var geochart = new google.visualization.GeoChart(
document.getElementById(‘visualization’));
geochart.draw(data, {width: 556, height: 347});
}

google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style=”font-family: Arial;border: 0 none;”>
<div id=”visualization”></div>
</body>
</html>
Here is the link to the page on my site http://stevestedman.com/samples/visualization1.html

I hope you enjoy this.

-Steve Stedman

Bellingham WA