SQL supports most aggregate functions except one fundamental aggregation to calculate product of values in a column. If you are wondering what could be a scenario where you may have to calculate product of values in a column, here is a business scenario that demands it. Business Scenario: For the sake of brevity, let's say... Continue Reading →
A Use Case of CROSS JOINS in SQL
Use case of SQL CROSS JOIN: Although CROSS JOIN is available in SQL, you rarely find any instance where you can use it. Here is one use case for CROSS JOIN in SQL: Example with fictitious data: Assuming a tournament of Soccer to happen among four teams, what are the all possible matches between each... Continue Reading →
Complement Negation: SQL Design Pattern to solve a frequently occurring interesting business data analysis problem
Here is an interesting business data analysis problem that I have come across multiple times in the recent times. Since I have seen this problem surfacing multiple times and the solution boils down to the same technique, it becomes an SQL Design Pattern and I named this baby as "Complement Negation". Have shared the justification... Continue Reading →
Single T-SQL query to swapping the values of two columns without using temporary column
How to swap the values of two columns of a table ? Let me explain the scenario with an example - Let's create a table named "Employees" with columns "First_Name" and "Last_Name". Then populate the table with some fictitious data. Then view the results once and then interchange the values in the "First_Name" and "Last_Name" columns... Continue Reading →
Comparing datetime column with a date literal in T-SQL
Hi Friends.. I have seen that comparing a datetime column in a table in SQL Server database, that has both date and time parts (e.g. 2012-12-05 10:37:36.897) with a date literal that has only date part is a not straight forward. Let me explain with an example: Have created a temporary table with two date... Continue Reading →