Modern applications often exchange information in JSON, and that data often ends up in SQL Server. While JSON’s flexible structure makes it ideal for storing dynamic or nested data, it doesn’t fit neatly into traditional relational tables. The good news is that SQL Server includes a good selection of JSON functions that let you parse, query, and transform JSON content into structured rows and columns. This means that you can work with your JSON data just like any other table.
convert
Using CAST() to Convert Rounded Values to Integers in SQL Server
Sometimes when you’re working with calculated columns in SQL Server, you might get results in a data type that’s less than ideal. For example, maybe it’s a decimal or float when you really need an integer. This can result in the output not appearing exactly the way you want, such as with a bunch of unnecessary trailing decimal zeros.
In such cases, you’ll probably want to remove these trailing zeros from the result. The CAST() function is perfect for this kind of cleanup. You can use it to convert the value to a more suitable type.
When to Use TRY_CONVERT() vs CONVERT() in SQL Server
Both CONVERT() and TRY_CONVERT() in SQL Server are used to convert data types, but they behave quite differently when something goes wrong. Understanding that difference can save you a lot of debugging time, especially when dealing with messy or unpredictable data.
Let’s look at when you should use each, and walk through an example that you can run yourself.
5 Ways to Convert DD/MM/YYYY to DATE in SQL Server
Converting a string in DD/MM/YYYY format to a DATE type can be done in several ways in SQL Server. This article presents five options along with examples.
Handling International Date Formats When Casting to DATETIME in SQL Server
Working with dates in SQL Server is usually quite straightforward. There’s a good range of date types and functions that we can use to manipulate date/time values.
But international date formats can undo all that simplicity in a heartbeat. Something as simple as casting a string into a DATETIME type can blow up depending on how the server interprets the input. This often happens when you’re dealing with applications or imports that don’t stick to a single culture or regional setting.
Let’s walk through an example and see why SQL Server behaves this way, and more importantly, how to handle it correctly.
Fixing Invalid Date Conversions in SQL Server
When you work with dates in SQL Server, you’ll often run into situations where a value can’t be converted directly to a datetime or date. This usually happens because the source data isn’t in a format SQL Server recognises, or because the value itself is out‑of‑range (e.g., “2025‑02‑30”). Fortunately, the built‑in conversion functions CAST() and CONVERT() provide us with enough flexibility to clean up those problematic values without resorting to messy string manipulation.
Below we’ll look at the most common scenarios, show how to diagnose the issue, and demonstrate how to fix it.
Top 5 Data Conversion Errors in SQL Server and How to Avoid Them
Data conversion errors can be a frequent source of frustration when working with databases. And SQL Server is no exception. Such errors can interrupt workflows and lead to inconsistent results. While data conversion errors often happen during explicit conversions, they aren’t unique to this. Oftentimes the error can be due to an implicit conversion.
This article outlines five of the most common data conversion errors and provides practical steps to avoid them.
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.
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.
The Difference Between CAST() and TRY_CAST() in DuckDB
DuckDB offers two primary functions for type conversion: cast() and try_cast(). While they serve similar purposes, their behavior when handling invalid conversions differs significantly, which can greatly impact our data processing workflows.