Functions

Manvendra Singh
Use SUM with other system functions and GROUP BY statement

Understanding the SQL SUM() function and its use cases

December 13, 2022 by

Today, I will describe the SQL SUM () function along with its use cases in this article. There are various mathematical calculations we need to do in day-to-day business requirements. SQL Server offers various system functions which I have listed below to get these mathematical calculations easily by using them. One such requirement is to get the sum of values stored in a numeric column. We can use SQL Server system function SUM () to easily get the sum of the values stored in a numeric column of the table.

Read more »
Manvendra Singh
security testing for SQL Server environments

Understanding security testing for SQL Server environments

March 3, 2022 by

This article will explain various aspects of security testing for the SQL Server environment. Security is a very critical area for any database environment. We must properly plan, deploy, and audit database security measures to protect and prevent any unauthorized access of the data. We should also perform regular security testing to ensure we have the right set of rules and policies in place to secure our database environment. Database security measures also help any organization to protect its data to maintain its privacy and integrity.

Read more »
Hadi Fadlallah
Working with JIT Compiler

Getting started with SQL Server CLR functions

January 11, 2022 by

This article will explain how to create a SQL Server CLR function stored in a C# class library without creating a SQL Server database project. We will first briefly explain the concept of .NET common language runtime (CLR) and then build a C# class library using the .NET framework. Then, we will use the C# library to create user-defined CLR functions in SQL Server.

Read more »
Manvendra Singh
Use GETDATE with DATEADD function

SQL Server GETDATE () function and its use cases

December 16, 2021 by

This article will discuss an overview and use cases of the SQL Server GETDATE () function which is used to return the current date and time of the system on which SQL Server instance is running. There are several date-time related functions in SQL Server for distinct requirements like SYSDATETIME, CURRENT_TIMESTAMP, etc. All these functions will return the current date-time of the system on which the SQL Server is running. The only difference of having these many functions is the accuracy of the length of timestamp like till what precision you want to return your date time output. I will show you the output of some of these date-time functions and compare them with SQL Server GETDATE () function.

Read more »
Manvendra Singh
Use case with GROUP BY statement

Understanding the SQL MIN statement and its use cases

December 3, 2021 by

Today, I will explain an overview of the SQL MIN () function along with its several use cases in this article. This function is categorized under aggregate functions in SQL Server. Aggregate functions perform a calculation on a set of values from a specified expression and return a single value in their output. Aggregate functions return the same value every time you execute them unless your source data is changed.

Read more »
Aveek Das
Using the FIRST_VALUE function

An overview of Analytic Functions in SQL Server

August 2, 2021 by

In this article, we are going to talk about the various analytic functions that are supported by the SQL Server Database Engine. As it goes by the name, these are some special functions using which we can execute analytic queries on the dataset and obtain useful results. In comparison to standard SQL queries, sometimes it becomes necessary for the Data Analysts to deep dive into the data more and obtain insights from analytic perspectives. This article will discuss all the analytic functions supported by SQL Server with some details.

Read more »
Esat Erkec
How to read a file of JSON in SQL Server with OPENJSON function

How to parse JSON in SQL Server

September 15, 2020 by

In this article, we will learn how to parse and query JSON in SQL Server with the help of the OPENJSON function. Firstly, we will briefly look at the data structure of the JSON and then we will learn details of the parsing and querying JSON data using the OPENJSON function.

Read more »
Jignesh Raiyani
Calling SQL Server Procedure inside the Function

Execute a SQL Server procedure inside a function

June 23, 2020 by

In this article, we will ensure that the execution of the SQL Server procedure inside the function is possible. A common understanding of the database developer is that the procedure cannot be utilized or executed inside a user-defined function because the user-defined function does not allow performing DML operation with the table. The procedure is allowed to play with the database and its property, whether a user-defined function isn’t. That should be the essential reason behind allowing the execution of a SQL Server procedure inside the function.

Read more »
Aveek Das
Child Function Executed

Calling an AWS Lambda function from another Lambda function

June 9, 2020 by

In this article, I am going to explain how to create an AWS Lambda function and then call this function from another Lambda function within the same region. This is a useful scenario in which we may need to execute a second lambda function based on the outcome of some previous logic. Another scenario may be to execute a second lambda function several times by using different parameters.

Read more »
Frank Solomon

Lever T-SQL for Pinpoint Control of ORDER BY in a Stored Procedure

June 1, 2020 by

Introduction

The T-SQL ORDER BY clause sorts SQL Server SELECT statement result sets, and it becomes important when we build stored procedures. Unfortunately, the syntax offers no flexible way to directly control the ORDER BY clause behavior with argument values. This means we don’t have an easy way to control the specific column or columns that the ORDER BY clause sorts. Additionally, SQL Server does not offer a flexible way to directly control the ascending or descending order of any ORDER BY clause column with argument values. Of course, we can certainly hard-code the ORDER BY clause in a stored procedure, but this approach becomes fixed in stone. We could try a dynamic SQL solution, involving a stored procedure code that dynamically builds and executes SQL Server statements inside a stored procedure. However, this technique becomes tricky, and it can lead to SQL injection attacks. Other techniques might rely on CASE statements, and their complexity can become overwhelming as the column count grows. This article spotlights a clean, efficient, pinpoint T-SQL stored procedure technique that directly sorts one, some, or all SELECT statement result set columns. The technique avoids dynamic SQL, and it operates directly in a stored procedure. The article also shows how to set the ascending or descending sort order of specific columns.

Read more »
Frank Solomon
Run the DYNAMIC_ROW_NUMBER_PARTITIONS stored procedure with a T-SQL EXEC statement, and see the result set.

Lever T-SQL to dynamically define duplicate SQL Server database table rows

May 11, 2020 by

Introduction

Lever T-SQL to handle duplicate rows in SQL Server database tables article highlighted T-SQL features that detect and handle duplicate SQL Server table rows. The techniques work well, but they rely on fixed duplicate row definitions. This article extends those techniques, showing how to define duplicate rows in a dynamic way.

Read more »
Esat Erkec
What is pagination in SQL Server?

Pagination in SQL Server

April 14, 2020 by

Pagination is a process that is used to divide a large data into smaller discrete pages, and this process is also known as paging. Pagination is commonly used by web applications and can be seen on Google. When we search for something on Google, it shows the results on the separated page; this is the main idea of the pagination.

Read more »