How to Unforce a Query Execution Plan in SQL Server

When you’ve forced an execution plan in SQL Server’s query store and later want to allow the optimizer to choose plans freely again, you’ll need to unforce the plan. You might want to do this because you’ve fixed the underlying issue or the forced plan is no longer optimal. Whatever the reason, the solution is straightforward and easy.

Read more

Generating Staggered Dates with SQL Server Window Functions

SQL Server’s window functions open up some creative possibilities when you need to work with dates. One interesting pattern involves pairing DATEADD() with ROW_NUMBER() to automatically generate sequential dates based on your query results.

This technique gives you a flexible way to calculate dates dynamically without hardcoding values or maintaining separate date tables. This can be useful for doing things like building a scheduling system, creating test data with realistic timestamps, or just spacing events across a timeline.

Read more

Understanding Locks in SQL Server

If you’ve ever wondered why your database queries sometimes seem to wait around doing nothing, or why two users can’t update the same record at the exact same moment, you’re dealing with locks. In SQL Server, locks are the fundamental mechanism that keeps your data consistent and prevents the chaos that would ensue if everyone could modify everything simultaneously.

Read more

Building a Survey Results Dashboard in SQL

Survey data can be messy. You’ve got responses scattered across dozens or hundreds of rows, multiple choice answers, rating scales, and so on. And the challenge of turning all that raw data into something stakeholders can actually understand. A well-designed survey dashboard can transform those individual responses into a grid that shows patterns instantly. For example, which questions are getting strong agreement, where opinions diverge, and what trends emerge across different respondent groups.

Read more

Calculating Dynamic Date Offsets with Expressions in SQL Server’s DATEADD() Function

One of DATEADD()‘s less obvious features in SQL Server is its ability to accept expressions as the interval parameter rather than just simple numeric values. You can perform calculations, use arithmetic operations, or reference multiple columns right inside the function call. This gives you a more flexible way to calculate dates when the offset itself needs to be computed based on your data.

So, instead of adding or subtracting a fixed number of days, months, or years, you compute that number on the fly using whatever logic makes sense for your situation. Let’s look at an example that demonstrates this concept.

Read more