TSQL: How to use LEAD() and LAG() functions in analytic data

Problems I have a data set that describe Sales data of all categories. Now I need to build a query to compare Sales of a given year with previous year for each category. For example, I have a data set of SALES Now, I need to build a report to analyze how much sales of previous year … Continue reading TSQL: How to use LEAD() and LAG() functions in analytic data

Advertisements

TSQL: Working with PIVOT in SQL Server

Problem You have a data in your database as below: So now, you need to build a report Sales By Branch Solution There are many ways to implement any report like above. The most popular way is PIVOT technique in SQL Server. Ideally, PIVOT is used to convert rows to columns. To understand how it works, … Continue reading TSQL: Working with PIVOT in SQL Server

TSQL: Pagination data with OFFSET and FETCH in SQL Server 2012

Scenarios In the prior SQL edition, you often use combination of ROW_NUMBER and ORDER BY whenever you want to implement pagination data in SQL Server. From SQL Server 2012, Microsoft announced a new functions to support pagination data. They are OFFSET and FETCH. In this article, I am going to introduce how to use them for … Continue reading TSQL: Pagination data with OFFSET and FETCH in SQL Server 2012