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
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
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
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
With SQL Server versions 2008R2 and 2012, you can access the registry to get the settings for the current instance of SQL Server. Here is how… Read More »Accessing the registry from TSQL on SQL Server 2012 and 2008R2
First for this example, and a few to follow we need to create the database that we are going to play around in. USE [Master];… Read More »ROWS PRECEDING and FOLLOWING in TSQL 2012
It has been a busy week getting ready for SQL Saturday Vancouver, planning sessions to present at future training’s and determining new material to present.… Read More »4 Sessions Submitted to Seattle Code Camp
After rebooting a SQL Server, for whatever reason, it is always good to confirm that the system is running good. There are many things that… Read More »Latest Backups with TSQL
Working on a new report for the SQL Server Health reports, I needed to display the amount of free disk space on a SQL Server.… Read More »Determining free disk space with TSQL
Just the same query that I posted months ago, but this time it is wrapped in a stored proc. I use this one often enough… Read More »Big One Time Use Queries – Revisited