-
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.…
-
Temporary Stored Procedures in SQL Server
Read more: Temporary Stored Procedures in SQL ServerPretty much every T-SQL programmer knows about temp tables very early in their journey with the language. They are generally wonderful tools that, when used properly, can be invaluable for storing data for a short amount of time. When used improperly they can be somewhat problematic, but certainly they are a tool we all use…
-
Fun with COUNT aggregate calls
Read more: Fun with COUNT aggregate callsI was reading LinkedIn posts the other day when I saw this blog about what was apparently an interview question about some forms of a COUNT aggregate function This was apparently asked in an interview. What will each of these constructs do in a SQL statement: The correct answers the poster gave were not the…


