From SQL Server 2022 we can use the JSON_PATH_EXISTS()
function to test whether a specified SQL/JSON path exists in the input JSON string.
It’s similar to the JSON_CONTAINS_PATH()
function that’s available in MySQL and MariaDB.
From SQL Server 2022 we can use the JSON_PATH_EXISTS()
function to test whether a specified SQL/JSON path exists in the input JSON string.
It’s similar to the JSON_CONTAINS_PATH()
function that’s available in MySQL and MariaDB.
In SQL Server, we can use the JSON_ARRAY()
function to construct JSON array text from zero or more expressions.
The resulting array contains the values we provide as arguments. Providing zero expressions results in an empty array.
Continue readingIn SQL Server, we can use the JSON_OBJECT()
function to construct JSON object text from zero or more expressions.
The resulting object contains the key/value pairs that we provide as arguments. Providing zero expressions results in an empty object.
Continue readingIf you’re using the GENERATE_SERIES()
function to create a series of numbers, but you’re finding that only the first value in the series is returned, it could be something very obvious.
The obvious reason this could happen is that your step value is too big. In particular, if the step is so big that it covers the whole series, then it stands to reason that there will only be one value in the series.
If this is an issue for you, you might want to check that you’re using an appropriate step value. Using a smaller step value can help to create a series with more values.
Continue readingThe release of SQL Server 2022 in November 2022 introduced a bunch of new functionality, including some enhancements to the TRIM()
, LTRIM()
and RTRIM()
functions.
The enhancements in the LTRIM()
and RTRIM()
functions are different to those in the TRIM()
function. Below is a quick overview of the enhancements to these functions, along with examples.
In SQL Server, the GENERATE_SERIES()
function is a relational operator that returns a series of values between a given start and stop point. These are returned in a single-column table.
Although the GENERATE_SERIES()
function only works with numeric values, we can combine it with other functions to create a series of dates.
The GENERATE_SERIES()
function was introduced in SQL Server 2022 (16.x) and requires the compatibility level to be at least 160.
The release of SQL Server 2022 came with the introduction of the DATE_BUCKET()
function.
The DATE_BUCKET()
function allows us to arrange data into groups that represent fixed intervals of time. It returns the date/time value that corresponds to the start of each date/time bucket, as defined by the arguments passed to the function.
In SQL Server, we can use the DATETRUNC()
function to truncate a date/time value to a specified precision.
For example, we could use it to truncate a date value like 2024-10-25 to 2024-01-01, or a time value like 10:35:12 to 10:00:00.
The DATETRUNC()
function was introduced in SQL Server 2022Â (16.x).
In SQL Server, we can use the TRIM()
function to remove leading and trailing characters from a given string.
A common use case is to remove whitespace from the start and end of the string, but we can also specify other characters to remove.
Also, as from SQL Server 2022, we can specify which side of the string to remove the characters from (i.e. leading, trailing, or both).
Continue readingIn SQL Server, we can use the T-SQLÂ RTRIM()
function to remove trailing blanks from a given string. Trailing blanks are white spaces, tabs, etc that come at the end of the string.
Also, as from SQL Server 2022, we can specify other trailing characters to remove from the string.
Continue reading