SQL Server and Set Operations
In this puzzle, we’re going to about SQL set operations. Set operations allow us to compare rows from two or more tables to arrive at a result. For several classes of problems, is is much easier to...
View ArticleHow to use SQL Union in Set Operations
In this puzzle, we’re going to learn how to write a SQL UNION without using Set Operations. Set operations allow us to compare rows from two or more tables to arrive at a result. For several...
View ArticleWhat is the difference between a primary and unique key?
In this article we learn the difference between a primary and unique key, and why both are important to maintaining a relational database structure. All the examples for this lesson are based on...
View ArticleCalculate a Running Total in SQL with Joins or Window Functions
There are several ways to calculate a running total in SQL. In this article, we will cover two methods: Joins, and Window Functions. We’ll first look at how to calculate the running total using an...
View ArticleTOP Clause in SQL
In this Video we’ll show you how to use the TOP clause to return a portion of the result. This comes in handy in situations you’re required to return the top or bottom ten entries of a list. This...
View ArticleIntroduction to Stored Procedures for SQLServer
After reading this article you will understand the benefits of stored procedures and how to create and execute them. All the examples for this lesson are based on Microsoft SQL Server Management Studio...
View ArticleUse IF…ELSE Statements to Program a Stored Procedure
After reading this article you will understand the basics of programming a stored procedure using IF…ELSE statements; most importantly how keywords, such as BEGIN, END, IF and ELSE affect the order of...
View ArticleUsing the WHILE Statement in Stored Procedures
After reading this article you will understand the basics of using the WHILE statement to write a loop within a stored procedure. All the examples for this lesson are based on Microsoft SQL Server...
View ArticleBuild Dynamic SQL in a Stored Procedure
After reading this article you will understand the basics of dynamic SQL; how to build statements based on variable values, and how to execute those constructed statements using sp_executesql and...
View ArticleWhat is the Difference between Inner and Outer Joins?
Both inner and outer joins can be used to combine data from two or more tables; however, there are some key differences! Read this article to find out each command’s strengths and when to use them. To...
View ArticleKnow when to use Cast versus Convert
In this article we’re going to explore the CAST and CONVERT functions to understand whether there are any significant differences worth knowing when we want to convert data from one type to another....
View ArticleCommon Table Expressions (Introduction to CTE’s)
Common Table Expressions or CTE’s for short are used within SQL Server to simplify complex joins and subqueries, and to provide a means to query hierarchical data such as an organizational chart. In...
View ArticleNon Recursive CTEs Explained and Why to Use Them
Introduction to Non Recursive CTEs In this article we explore non recursive CTEs (Common Table Expressions). This is a broad class, and basically covers every form of CTEs except those that call...
View ArticleRecursive CTEs Explained
Recursive CTE’s In this article we explore recursive CTE’s (Common Table Expressions). Recursive CTEs are special in the sense they are allowed to reference themselves! Because of this special...
View ArticleCalculate the Last Day of the Month using SQL
When working with SQL dates, sometimes you need to calculate the end of the month. Months are tricky! Some are 28 days, others 30 or 31, and now and then there’s a leap year! So, given a date, how do...
View ArticleUncommon SQL Server Data Types
In this article we’re going to go over a uncommon SQL server data types. These are those you won’t use every day, but you’ll want to know if you take the 70-461 exam. Even if you don’t plan on taking...
View ArticleLearn How to Combine Data with a CROSS JOIN
A cross join is used when you wish to create combination of every row from two tables. All row combinations are included in the result; this is commonly called cross product join. A common use for a...
View ArticleLearn how to Add, Remove, or Modify values in a SQL Table
In this article we’ll discover data modification statements used to modify data in SQL server using the INSERT, UPDATE, DELETE, and MERGE statement. The SELECT, INSERT, UPDATE, DELETE, and MERGE...
View ArticleSQL INSERT Statement for SQL Server
Use the INSERT statement is to add rows to a SQL Server data table. In this article we explore how to use the INSERT statement. We discuss best practices, limitations, and wrap-up with several...
View ArticleUse SQL UPDATE to Query and Modify Data
The SQL UPDATE statement is used to change data within columns of a SQL Server data table. In this article we’ll explore how to use the UPDATE statement. We discuss some best practices, limitations,...
View ArticleIntroduction to the Delete Statement
The DELETE statement is used to remove rows from a SQL Server data table. In this article we’ll explore how to use the DELETE statement. We discuss some best practices, limitations, and wrap-up with...
View ArticleIntroduction to the Merge Statement
Introduction to the MERGE Statement and SQL Server Data Modification The MERGE statement is used to make changes in one table based on values matched from anther. It can be used to combine insert,...
View ArticleWhat is the Difference Between Merge and Update?
When modifying one table based on the contents of another it may be tempting to simply use the merge statement, but before you throw away all other forms of modifying data, I think it’s important for...
View ArticleCommon Data Types used in SQL Server
In this video we’ll walk you though the common data types used in SQL Server; you’ll see examples of each type’s values, and how to define them. Once you’ve gone through this article, I would recommend...
View ArticleHow to Make a Join Easier to Read using Table Aliases
I recently put together a lesson on table aliases and multi-table joins. It is part of my Join Together Now course. Click here get the course at a discount. You’ll find that as you write more...
View ArticleWhat is a Non-Equi Join in SQL and What is its Purpose?
I recently put together a lesson on non-equi joins. It is part of my Join Together Now course. Click here get the course at a discount. A non-equi join can be used to solve some interesting query...
View ArticleHow do I handle a “Error converting data type” error?
A reader recently asked about a error converting data type error they received. Since this is a common issue, especially when numeric data is stored withing VARCHAR datatypes, I thought you would...
View ArticleDebugging Stored Procedures in SQL Server
I recently put together a lesson on debugging stored procedures. It is part of my Stored Procedures Unpacked course. When you debug stored procedures, you’re able to run their code line by line, to...
View ArticleWHILE Loops in T-SQL Stored Procedures
In this lesson, we’re going to learn about the While Loop. So, what is a While Loop? Well, While Loop is set up using a While statement. While statements are used to repeatedly execute a block of SQL...
View ArticleGet Started with Power BI Desktop
This is the first in a series of articles on how to Get Started with Power BI. For those of you unaware, Microsoft Power BI is an analytics tool you can use to create interactive visual reports. The...
View ArticleCreate a SQL Pivot Table in Six Steps
In this episode of SQL Minute I want to share with you how to create a pivot or cross tab chart. I’ll show you the steps using an example from the adventure works database. I get so many questions on...
View ArticleCan I have a CASE Statement in the WHERE Clause?
A common question I get ask is whether I can have a CASE Statement in the WHERE Clause. There are so many examples of CASE being used in SELECT columns, or in ORDER BY that we tend to forget CASE can...
View ArticleUse hierarchyid to query Hierarchical data
In this SQL minute we’ll look at how you can use hierarchyid to query hierarchy data. This is a two-part article. In this article we look at how to do one query to get portion of the hierarchy....
View ArticleSQL Server Hierarchical Query using the hierarchyid type
In this SQL minute we’ll look at how to create a SQL server hierarchical query using the hierarchyid data type. This is a two-part article. In part one you were introduced to the hierarchyid type....
View ArticleSQL COALESCE Function and NULL
Knowing when to use the SQL COALESCE function is a lifesaver when you’re dealing with NULL. As you know, NULL is a tricky concept, and it seem what ever NULL “touches” in an expression, it renders the...
View ArticleRank Data with SQL
In this puzzle, we’re going to work through a problem to identify the top and bottom 25 percent to rank student scores. Solving puzzles is a great way to learn SQL. Nothing beats practicing what...
View ArticleSQL Puzzle: How to Calculate Moving Averages
In this puzzle, we’re going to learn how to calculate moving averages by working through a hypothetical stock market example. Solving puzzles is a great way to learn SQL. Nothing beats practicing what...
View ArticleReturn the first rows from your result.
In this video we’ll walk you though how to select top rows within a query. We’ll show you how to retrieve the top or bottom rows in the result. We’ll also show you how to use one sort to select the...
View ArticleHow to Find a Gap in a Sequence using SQL SERVER
In this puzzle, we’re going to learn how to find a gap in a sequence using SQL Server. I was recently reviewing my bank statement and noticed they flagged the start of a missing check number with...
View ArticleHow do I use the Like Clause in SQL Server?
In this video we’ll walk you though how to use the LIKE clause. We’ll show you how to you can perform partial matches, such as being able to match all names beginning with “B” or ending in “Y.”...
View ArticleHow to Create A Bar Chart Using SQL Server
We are going to learn how to create a bar chart using SQL server in this puzzle. It can sometimes be fun to see what you can do with the SELECT statement. Besides, I figured it would be fun to see if I...
View ArticleUse Subquery with Bill of Materials
In this puzzle, we’re going to learn how to work with the AdventureWorks Bill of Materials table. Companies use a BOM (Bill of Materials) to itemize the products that are used or contained in another...
View ArticleLearn how to Work Joins and Messy Data
In this puzzle, we are going to learn how to join dirty data using the SQL Server. There are many instances that you are forced to use someone else’s data. Since it is their system and data (not...
View ArticleUse SQL Server to Create a Cross Tab Query
In this puzzle, we’re going to learn how to create a cross tab query using SQL Server. Cross tabs are a great way to summarize data. And given that Business Intelligence is a hot topic, knowing how...
View ArticleWhat is a Dynamic Pivot Table?
In this puzzle, we’re going to learn how to create a dynamic pivot table using SQL Server. A dynamic pivot table is a great way to summarize data. And given that Business Intelligence is a hot topic,...
View ArticleLearn to use the Data Dictionary in SQL Server
In this puzzle, we’re going to learn how to query the data dictionary using SQL Server. Knowing how to query the data dictionary is good to know. There are many questions you can answer about your...
View ArticleUse SQL to Calculate Median Values.
In this puzzle we’re going to learn how to find the person whose birthday, among others, is in the middle. Knowing how to calculate the median value is a good skill to have. As you start to explore...
View ArticleWhat is the difference between a subquery and inner join?
In this puzzle, we’re going to learn how to rewrite a subquery using inner joins. Knowing about a subquery versus inner join can help you with interview questions and performance issues. Though...
View ArticleJoins versus Subqueries SQL Puzzle
In this puzzle, we’re going to learn about joins versus subqueries. In many queries you can substitute joins and subqueries. Yet, since each has their strengths, it isn’t wise to do so. Once you...
View ArticleData Modeling Principles in Action
In this puzzle, we’re going to learn how to do some basic data modeling. Many of you have expressed an interest in learning more about data modeling and database design. I figure we could start with...
View Article