Category «Queries»

How to Use the OVER Clause in SQL Server 2008 R2

This tutorial will show how to use the OVER clause in SQL Server 2008 R2. The OVER clause exposes a window of rows to certain kinds of calculations. The window of rows is simply a certain set of rows that the calculation operates on. Only Aggregate and ranking functions are the types of calculations that …

How to Count Distinct Values in a Table In SQL Server

This tutorial will show how to create a query that retrieves a count of unique values in a column of a table. To make this query work, we will use the COUNT function and the DISTINCT statement. The COUNT function returns the number of rows that matches a specified definition and the DISTINCT statement can be …

How to Use the GETDATE Function in SQL Server

This tutorial will show you how to use the GETDATE function in SQL Server. The GETDATE function retrieves the current date and time from the SQL Server at run time. This function is very useful when working with time sensitive material, such as order dates. In this tutorial we will create a table of called …

How to Use Wild Cards in SQL Server

In this tutorial you will learn how to use wildcards in SQL Server. SQL wildcards can be used when searching for data in a database. SQL wildcards are used with the LIKE operator, which acts as a comparison when searching the database.  We will use the ‘%’ and ‘_’ wildcards in SQL Server: % – A substitute for zero or …

How to Use the CASE Expression in SQL Server

In this tutorial you will learn how to use the CASE expression. A CASE expression is given a value that runs through the conditional logic and returns a value. Because CASE can hold only one value at a time, it is allowed with similar expressions such as the SELECT, WHERE, HAVING, and ORDER BY clauses. …