Geek Logbook

Tech sea log book

Understanding the DECIMAL Data Type in SQL: What Happens When You Don’t Specify Parameters?

When working with SQL, one of the fundamental aspects of database design and manipulation is understanding the various data types available. Among them, the DECIMAL type is often used for representing numbers that require a high level of accuracy, such as financial data. But what happens when you don’t specify parameters for a DECIMAL column

Understanding Window Functions in SQL with Running Totals

Introduction Window functions in SQL are incredibly powerful, allowing you to perform calculations across a set of table rows related to the current row. They enable tasks like calculating running totals, generating rankings, and more, all while maintaining individual row-level detail. In this post, we’ll dive into window functions, focusing on how to calculate a

Debugging SQL Joins: Troubleshooting OR Joins with Multiple Columns in PostgreSQL

Introduction SQL joins are essential for combining data from different tables in a relational database. However, they can sometimes be tricky, especially when dealing with complex joins that involve multiple columns or need to account for variations in data structure. In this post, we’ll walk through a real-world scenario where a SQL join on multiple

Retrieving the Name of an SQL Script File in Your Query

When working with SQL scripts, there are times when you might want to dynamically retrieve the name of the script that is currently executing. Unfortunately, SQL itself doesn’t provide a straightforward method to access the name of the script file directly. However, depending on your database system and the tools you are using, there are

Decrypting Encrypted Data with Subqueries in SQL

When working with encrypted data in SQL, it’s essential to ensure that the decryption process is secure and efficient. One effective approach is using subqueries. In this post, we’ll demonstrate how to use subqueries to decrypt encrypted data, perform transformations, and filter results based on specific criteria. Scenario Let’s assume we have a table [YOUR_DATABASE].[YOUR_TABLE]

Extracting the Last Part of a String in SQL Server

Introduction When working with SQL Server, you might often encounter scenarios where you need to extract a specific part of a string. For example, you might have a string in the format DATA_TYPE_001_SAMPLE and you want to extract the last part, SAMPLE. In this blog post, we will explore how to achieve this using SQL

Leveraging SQL Window Functions with PARTITION BY

SQL window functions are a powerful tool for performing calculations across a set of rows related to the current row. When combined with the PARTITION BY clause, these functions can provide deep insights into your data by breaking it into partitions, allowing you to perform calculations within each partition separately. In this post, we will

Extracting Substrings from Strings in SQL Server

When working with SQL Server databases, you may often encounter scenarios where you need to extract specific parts of a string based on a pattern. A common requirement is to retrieve the substring that follows the last underscore (_) in a given string. This blog post will demonstrate how to achieve this using SQL Server

Common table expressions

Specifies a temporary named result set, known as a common table expression (CTE). Microsoft Documentation Although there are some time around us the first time someone asked me about it I was confused: I haven’t know its proper definition until that momento. In fact, the common table expressions where added to the SQL standard in