Tags » T-SQL

Switching Rows and Columns

Often the way we display our data differs from how we store it.  Sales are a good example; in your table each row contains a sale.   1,093 more words

Sql Server

Stored Procedures

A Stored Procedure is a set of SQL statements followed by an assigned name, that is stored in the database. This will be in a compiled form and has the ability to be shared by multiple queries. 342 more words


SQL: SQL Server format decimal places with commas

Convert to money then convert to varchar with formatting option 1:
SELECT CONVERT(varchar, CAST(1112 AS money), 1)

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


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. 487 more words


TSQL: Working with PIVOT in SQL Server


You have a data in your database as below:

So now, you need to build a report Sales By Branch


There are many ways to implement any report like above. 340 more words


Which databases were backed up in which backup task?

It’s a confusing question / title / headline. Let’s see if I can clarify what I’m after.

For each scheduled backup job, which databases were backed up? 2,045 more words

SQLServerPedia Syndication

Simplifying Complex Queries

When it comes to complex queries which contains multiple sub queries, the performance of the query tends to decrease. Apart from performance, the readability of the code also plays a huge role, specially when you have to trace back in order to refer to a certain condition or function. 335 more words