Gregory Larsen

Currently a SQL Server DBA. I've been working with SQL Server since 1999. I'm an old-time mainframe DBA. My DBA career started in 1985. Currently studying to obtaining MCDBA.

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 5: Turning Data On Its Side Using PIVOT Operator

The PIVOT operator was added to the Transact-SQL language in SQL Server 2005. It allows you to turn your row data on its side, so it can be presented as column data. This is useful when you want take unique column values and have them displayed as column headings, where the column headings are associated with summarized values displayed below each column heading. In this article I will be exploring how to use the PIVOT operator.

4 (4)

You rated this post out of 5. Change rating

2024-04-24 (first published: )

23,976 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 4: Record Level Processing Using Transact-SQL Cursors

Using a CURSOR is not normally the best way to process through a set of records. Yet when a seasoned programmer moves to writing TSQL for the first time they frequently look for ways to process a sets of records one row at a time. They do this because they are not used to thinking about processing records as a set. In order to process through a TSQL record set a row at a time you can use a cursor. A cursor is a record set that is defined with the DECLARE CURSOR statement. Cursors can be defined as either read-only or updatable. In this article I will introduce you to using cursors to do record level processing one row at a time.

4.67 (3)

You rated this post out of 5. Change rating

2024-04-10 (first published: )

13,255 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 3: Understanding Common Table Expressions (CTEs)

A CTE is a temporary result set defined by a simple query, and is used within the execution scope of a single INSERT, UPDATE, DELETE, or SELECT statement. In this article we will explore how to define and use CTE's.

You rated this post out of 5. Change rating

2024-04-03 (first published: )

5,536 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 2: Using the APPLY Operator

The APPLY operator allows you to join a record set with a function, and apply the function to every qualifying row of the table (or view). The APPLY operator takes on two formats: CROSS APPLY, or OUTER APPLY. This article will explain the differences between these two formats, and show you examples of how each of these formats work.

4.88 (8)

You rated this post out of 5. Change rating

2024-03-13 (first published: )

28,998 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 1: Intro to Advanced T-SQL Using a CROSS JOIN

The first installment of this new stairway series will be discuss the CROSS JOIN operator. This stairway should help readers prepare for passing the Microsoft Certification exam 70-461: Querying Microsoft SQL Server 2012.

5 (4)

You rated this post out of 5. Change rating

2024-03-06 (first published: )

36,916 reads

Transact-SQL: The Building Blocks to SQL Server Programming eBook by Gregory A. Larsen

Transact-SQL: The Building Blocks to SQL Server Programming by Gregory A. Larsen

Transact SQL (TSQL) is the languaged used to query and update data stored in a SQL Server. This book, written by SQL Server Central and Simple Talk author Greg Larsen, will give developers an understanding of the basics of the TSQL language. Programmers will have the building blocks necessary to quickly and easily build applications that use SQL Server.

You rated this post out of 5. Change rating

2024-03-06 (first published: )

9,963 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 7: Ordering Your Data Using Ranking Functions

In SQL Server there are 4 different ranking functions: RANK, DENSE_RANK, NTILE, and ROW_NUMBER. These ranking functions were introduced in SQL Server 2005. In this stairway level I will be reviewing each of these different ranking functions, and will show you how to use them by providing a few examples.

5 (4)

You rated this post out of 5. Change rating

2022-07-06 (first published: )

17,011 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 11: Using Logical Operators

SQL Server supports a number of different logical operators.  These operators can be used for testing Boolean conditions that return true, false and unknown in your T-SQL code.  Logical operators are useful for defining constraints to limit the rows be processed when selecting or updating data. This chapter will provide an overview of the logical […]

4 (1)

You rated this post out of 5. Change rating

2022-04-20 (first published: )

3,627 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 6: Creating Rows Of Data Using The UNPIVOT Operator

The UNPIVOT operator does just the opposite of the PIVOT operator, which we looked at in the previous level. By using the PIVOT operator we can take multiple rows of data and create as single row as output. The UNPIVOT operator will take values from a single row and will create multiple rows. Microsoft introduced the UNPIVOT operator when they rolled out SQL Server 2005. In this level I will be showing you different examples of how to use the UNPIVOT operator.

You rated this post out of 5. Change rating

2022-01-05 (first published: )

11,505 reads

Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 9: Compare, Modify, Derive and Validate Date and Time Values

When you build applications that store data in SQL Server you will most likely have to store dates and times, and you’ll call functions to do date manipulations. It is important to understand the different date and time data types, and when to use one data type over another. In this level I will be exploring the different date and time data types and discussing when each type is appropriate.

4 (1)

You rated this post out of 5. Change rating

2021-12-29 (first published: )

13,376 reads

Blogs

Friday Basics: the CIA Triad

By

In information security (INFOSEC), there several foundational concepts and principles. One of the ones...

A New Word: the standard blues

By

the standard blues– n. the dispiriting awareness that the twists and turns of your...

How Redgate Flyway Can Boost Your DevOps Journey

By

A brief introduction to the tool and its advantages for database migrations DevOps is...

Read the latest Blogs

Forums

One more reason to use foreign key constraints

By Louis Davidson (@drsql)

Comments posted to this topic are about the item One more reason to use...

client_app_name is empty in Extended Events output but present in sp_who2

By Pete Bishop

I'm tracing activity on one database and would like to include the client_app_name in...

How to compare data in customer table with other customers to find related cust

By Zond Sita

select Custno, Addr1, City, Res_Phone, Bus_Phone, Fax_Phone, Marine_Phone, Pager_Phone, Other_Phone, email1, email2 from customer...

Visit the forum

Question of the Day

The Marked Transaction

I want to mark a transaction in the log as a recovery point. How do I do this in my code if I use the transaction, myTran?

See possible answers