IIF in TRANSACT SQL on SQL SERVER 2012
For years I have heard the question of how can I do an IIF in TSQL? Honestly I never thought it would be that useful… Read More »IIF in TRANSACT SQL on SQL SERVER 2012
For years I have heard the question of how can I do an IIF in TSQL? Honestly I never thought it would be that useful… Read More »IIF in TRANSACT SQL on SQL SERVER 2012
Over the last week I have pitched 8 presentations for SQL Connections in Vegas at the end of October 2012. Hoping that 3 of my… Read More »Working on my Presentations for SQL Connections Fall 2012
A couple years ago in my Incident Safety Officer class with the fire department we studied risk assessment for any incident that the fire department… Read More »Risk Assessment Matrix for SQL Server Upgrades
After the last post on Cumulative Distribution Function (CDF) or as it is known in TSQL CUME_DIST(), I realized that although I showed how to… Read More »Cumulative Distribution Function (CDF) – Analyzing the Roll of Dice with TSQL
Continuing on the TSQL 2012 Analytic Series now on to the CUME_DIST function SQL Server 2012 introduces another new analytic function. The Cumulative Distribution Function… Read More »More TSQL 2012 Analytics CUME_DIST – Cumulative Distribution
Like the other new Analytic functions, PERCENTILE_DISC and PERCENTILE_CONT require the use of the OVER clause. For this example I will be using almost the… Read More »More TSQL 2012 Analytics PERCENTILE_DISC and PERCENTILE_CONT
The OUTPUT clause is often times underappreciated by the TSQL programmer. There are many really interesting things that you can do with the OUTPUT clause,… Read More »Using the OUTPUT Clause in TSQL for Auditing
Percent rank is defined as the number of values that are the same or less than the current value divided by one less than the… Read More »More TSQL Analytic Functions – PERCENT_RANK
SQL Server 2012 introduces 8 new analytic functions. This post will cover 2 of them LEAD and LAG, which can be used to reference a… Read More »TSQL Analytic Functions LEAD and LAG
In a previous article I covered the usage of ROWS PRECEDING and FOLLOWING in the over clause. For this example I am going to use the same database and tables that I created in the previous example to show ROWS UNBOUNDED both PRECEEDING and FOLLOWING.
One of the new features available in TSQL in SQL Server 2012 is the ROWS UNBOUNDED PRECEDING and the ROWS UNBOUNDED FOLLOWING options. The UNBOUNDED option in available when using the PRECEDING and FOLLOWING options. Here’s how they work…
-- ROWS UNBOUNDED PRECEDING select Year, DepartmentID, Revenue, min(Revenue) OVER (PARTITION by DepartmentID ORDER BY [YEAR] ROWS UNBOUNDED PRECEDING) as MinRevenueToDate from REVENUE order by departmentID, year;
In this example, the MinRevenueToDate lists the lowest revenue for this row and all earlier rows ordered by date in the current department id.
You can see that row 1 sets the MinRevenueToDate to 10030, and it doesn’t change until row 7 with a lower revenue year.
Read More »Transact SQL OVER Clause – ROWS UNBOUNDED PRECEDING or FOLLOWING