In SQL Server, when working with temporary tables, it’s common to ensure a temp table with the same name doesn’t already exist before creating it. This prevents any unwanted errors. SQL Server doesn’t support CREATE TABLE IF NOT EXISTS like some other DBMSs do, so you must explicitly check and drop the table beforehand.
DBMS
Database Management Systems
Converting Between Time Zones in SQL Server with AT TIME ZONE
Converting between time zones in SQL Server has evolved throughout the years. Prior to SQL Server 2016, there was no simple, built-in function to handle this task. We had to use a complex, multi-step approach involving functions like SWITCHOFFSET() and TODATETIMEOFFSET(), and we had to manually account for Daylight Saving Time (DST) rules for each time zone. This method was often prone to error and required constant maintenance to keep up with changing time zone and DST regulations.
How to Limit a Date Range to Just Business Days in DuckDB
DuckDB enables us to easily generate a range of dates, for example by using the generate_series() function and specifying the start date and end date. But what if you need to limit the output to just those dates that are business days?
This article provides an easy way to get that result.
Convert DDMMYYYY to DATE in SQL Server
Sometimes you might get dates in a non-standard format, such as DDMMYYYY. By “non-standard” I mean a format that SQL Server doesn’t recognize as a date. Such a format is actually a little ambiguous. Some dates presented in this format could be mistaken for another date. For example, 02082026 could be August 2, 2026, or it could be February 8, 2026 depending on which locale you’re using.
Therefore, we need to do a bit of work in order to get SQL Server to recognize it as a date. Once that’s done, it’s a simple matter of converting it to an actual DATE type.
Below are a few options for converting a DDMMYYYY string to a DATE in SQL Server.
Create an Azure SQL Database for Free
Azure SQL Database is a fully managed cloud database service used by organizations of all sizes, from startups to large enterprises. It provides high availability, scalability, and security out of the box while supporting the familiar SQL Server engine. Because it runs entirely in the cloud, you can build data-driven applications without managing hardware or dealing with routine maintenance.
Even though it’s built mainly for enterprise-grade workloads, Azure SQL can also be a great choice if you’re a developer or student who wants to learn SQL, build prototypes, experiment with cloud-based apps, etc.
And Microsoft offers us a free option, so you can do it all at no cost.
Getting Started with Azure Sign Up
Azure is Microsoft’s cloud computing platform that offers a wide range of services, including databases, virtual machines, and analytics tools. For SQL developers, Azure provides tools like Azure SQL Database and Azure Data Studio, which make it easy to build and scale applications in the cloud.
Even though Azure is built with enterprise scenarios in mind, Azure SQL provides a flexible platform for SQL developers and students to learn, prototype, and experiment in the cloud.
Below are the steps I used to sign up with Azure. I did this in order to take advantage of the free SQL database offer (which provides free access to a SQL database for life). But for the purpose of this article, we’ll look solely at the sign up process, as you’ll need to do this regardless of whether you’re doing the free SQL database thing.
How to Use STRING_AGG() in SQL Server with Custom Separators and Sorting
In SQL Server, STRING_AGG() is an aggregate function that concatenates string values from a group into a single string. It’s a handy tool for doing things like creating comma-separated lists from related data.
In this article we’ll check out how to use STRING_AGG() with different separators. We’ll also see how we can control the order of the concatenated strings.
4 Ways to Format the Current Date as MM/DD/YYYY in SQL Server
In SQL Server, we can use functions like GETDATE() to get the current date and time. There are also other functions, like CURRENT_TIMESTAMP, SYSDATETIME(), etc. These functions return values using one of the valid date/time types. For example, GETDATE() and CURRENT_TIMESTAMP return a datetime type, while SYSDATETIME() returns a datetime2(7) value.
Either way, if we want the current date to be displayed using MM/DD/YYYY format, we’ll need to do some extra work.
Fortunately SQL Server provides us with a range of options for doing this, and so we can pick the one that suits our scenario.
With that in mind, here are four ways to format the current date as MM/DD/YYYY in SQL Server.
When to Use CONVERT() vs CAST() for Date Formatting in SQL Server
When formatting dates in SQL Server you may be wondering whether to use CONVERT() or CAST(). After all, both functions allow us to convert between data types. Let’s take a look at at these two functions and figure out when to use each one.
5 Ways of Checking the Existence of Temporary Tables in SQL Server
When working with temporary tables in SQL Server, one of the most common tasks is checking whether the table already exists before creating it. This prevents errors in the event the table already exists, and ensures your scripts run smoothly regardless of previous executions.
In this article, we’ll explore five different approaches to checking for temporary table existence in SQL Server.