-
A short myth to look at: subqueries in the SELECT clause
Read more: A short myth to look at: subqueries in the SELECT clauseThis past week, I was sick and so I didn’t hang around social media much. But as I got better, I found more and more of the types of posts that just scream “I don’t know what I am talking about” from the poster. This was a pretty easy topic for the day, so I…
-
An interesting concept: Splitting queries with OR for performance
Read more: An interesting concept: Splitting queries with OR for performanceIn a recent LinkedIn post, a poster had a novel idea. Say you have a query that has an OR condition. Usually the OR condition in question are related concepts (like this UserId or another one), but sometimes they are quite distinct (like ProductCost is in a range, and ProductColor is in a list of…
-
The myth and the truth of filtering early
Read more: The myth and the truth of filtering earlyAn interesting phenomena has been occurring in LinkedIn that I really find interesting. It is the very repeated half truth. It is a concept that is true enough in some ways, but also wrong enough to cause confusion in people who are just learning. Transferring my primary social media use to LinkedIn has been a…
-
Define the question before writing the query
Read more: Define the question before writing the queryI am writing a presentation to do a couple of times this year on SQL techniques you ought to know. In the abstract, I defined the story as basically, you get an urgent request for a new report that does some aggregation and I am going to give you some techniques to help you out.…
-
Datatype precedence and finding the datatype of an expression
Read more: Datatype precedence and finding the datatype of an expressionThere is one topic in query and equation writing that is constantly a minor issue for SQL programmers: implicit data type conversions. Whenever you don’t specifically state the datatype of an expression, like when you write SELECT 1;, it can feel a bit of a mystery what the datatypes of your literal values are. Like…
-
Creating data from literal values in SQL Server
Read more: Creating data from literal values in SQL ServerNote: This is a post from the past being updated. The original post is here: 2008: Initializing Table Data with Row Constructors.. The code used here is the code I reference in this post on Redgate’s Product learning site: SQL Prompt AI Versus Smart Quotes, since the original post is rife with smart quotes! Row…
-
A SQL method for computing rolling totals without window functions
Read more: A SQL method for computing rolling totals without window functionsSay you want to find the most recent 30-day period during which a person purchased some amount of products from your company. How you market to a customer might change if they have been active over a time period recently, or even in the past. But this also means that for each day going back…
-
This post is not only about SELECT *
Read more: This post is not only about SELECT *I was about to walk out the door to take a flight, when my phone rang. Our major software system we had just released last week was returning weird data. FirstName and LastName was being reversed. I missed my flight because someone wrote SELECT * instead of SELECT FirstName, LastName and a table structure was…
-
Using TRANSLATE in SQL Server instead of REPLACE
Read more: Using TRANSLATE in SQL Server instead of REPLACESo the other day I was doing some data cleanup tasks, trying to format various values in a first name column. Needless to say, not everyone takes the task of giving a first name as sensically as you might imagine. And sense you generally don’t want to stop anyone from having any name they want.…


