For more information on cursors, also take a look at the free SQL query training provided by Steve Stedman. Cursors are a feature of SQL Server that allow users to iterate through a result set one row at a time. This can be useful in situations where a user needs to perform a set of operations on each row of a …

T-SQL: A Simple Example Using a Cursor Read more »

In my Common Table Expressions presentation the topic of recursion often comes up, but for scalar functions in T-SQL, it might not be as common. This article has been written to show how a scalar function in SQL Server can call itself, thus being considered recursive. The example uses a recursive scalar function to calculate the Fibonacci sequence. What is …

Recursive Scalar Function in T-SQL Read more »

Here is a quick rundown on the T-SQL DATEPART function for SQL Server. DATEPART is used to pull a single part of a date/time element out as shown below. The following query uses DATEPART to extract the year from the datetime input. The following query uses DATEPART to extract the quarter from the datetime input. The following query uses DATEPART …

T-SQL DATEPART Explained Read more »

My Common Table Expression presentation was accepted for SQL Saturday 212 in Redmond WA. This is the session that I am the most familiar with, and that I have presented the most times. I think this will be the 8th time I have presented this session, and after every previous presentation it has been improved. Over the last several months …

Common Table Expression accepted for SQL Saturday 212 in Redmond WA Read more »

SQL Server 2012 adds a new function called DateFromParts.  This new function simplifies the creating of a DATE type in TSQL over the older ways of doing it. The information here has been extracted from my SQL Saturday presentation on Whats New in TSQL 2012. Pre-SQL 2012 First lets take a look at how you would do the equivalent to DateFromParts before SQL …

DATEFROMPARTS function in TSQL Read more »

SQL Server 2012 adds many new features to Transact SQL (T-SQL).  One of my favorites is the Rows and Range enhancements to the over clause. These enhancements are often times referred to as the windowing functions. Want to learn more about the windowing functions? Check out this aggregation class that I have created: Overview:ROWS PRECEDING, FOLLOWING, UNBOUNDED, refers to the …

Rows and Range, Preceding and Following Read more »

SQL Server 2012 adds a new stored procedure called sp_describe_first_result_set.  This new procedure returns metadata for the result set returned from a query. The metadata is information about what the results will look like.  sp_describe_first_result_set is an alternative to sp_columns, and appears to perform much better than sp_columns. The information here has been extracted from my SQL Saturday presentation on Whats New in TSQL …

T-SQL 2012 Procedure sp_describe_first_result_set Read more »

# The key to twitter is to follow the right hash tags.  What hash tags do you follow related to Microsoft SQL Server? Here are a few of the twitter hash tags that I follow: #SQLServer The generic SQL Server hash tag. Most anything goes on this hash tag. #SQLHelp The #SQLHelp hash tag is great when you need to …

What twitter hash tags do you follow for SQL Server? Read more »

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: and another anniversary query (which doesn’t actually run): 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 …

Happy Birthday SQL Server 2012 Read more »

SQL Server 2012 introduces a new T-SQL object used to generate numbers, a SEQUENCE, similar to an identity column. You can think of a sequence as a take a number object, you just ask it to give you a number, and you get a number. When creating a SEQUENCE you need to specify the following: Start Increment Min Value, Max Value Cycle / …

Using a SEQUENCE object to generate letters. Read more »