SQL Server 2022 introduced the SET_BIT()
function that sets a bit in an integer or binary value (other than a large object).
The function allows us to specify an offset for which to set a bit to 1
or 0
.
SQL Server 2022 introduced the SET_BIT()
function that sets a bit in an integer or binary value (other than a large object).
The function allows us to specify an offset for which to set a bit to 1
or 0
.
Many RDBMSs support the concept of named windows – windows that we can reference from within an OVER
clause when defining a window function.
For those of us using SQL Server, we had to wait until the release of SQL Server 2022 before we could create named windows for our window functions. But with the release of SQL Server 2022, we now have the option of using named windows in our window functions.
Continue readingIn SQL Server, RIGHT_SHIFT()
is a bit manipulation function that returns the first argument bit-shifted right by the number of bits specified in the second argument.
The RIGHT_SHIFT()
function was introduced in SQL Server 2022.
If you’re getting SQL Server error msg 9837 that tells you “The date value is less than the minimum date value allowed for the data type…”, it sounds like you’re using the DATETRUNC()
function with the week
date part on a date that would cause the result to backtrack to a date that’s earlier than the date type supports.
This is a rare error that only occurs when using the week
date part with the DATETRUNC()
function on a very small number of early dates.
One way to deal with this error would be to use iso_week
instead of week
, if that’s suitable for your particular situation.
In SQL Server, LEFT_SHIFT()
is a bit manipulation function that returns the first argument bit-shifted left by the number of bits specified in the second argument.
The LEFT_SHIFT()
function was introduced in SQL Server 2022.
The introduction of the LEAST()
and GREATEST()
functions in SQL Server 2022 were a welcome addition. These functions enable us to get the minimum or maximum value from a list of values. There are plenty of use cases for these functions.
One such use case is to provide a cap on the values returned by a query.
Continue readingIf you’re getting SQL Server error 402 that reads something like “The data types numeric and numeric are incompatible in the approx_percentile_disc operator“, it’s probably because you’re trying to use the APPROX_PERCENTILE_DISC()
function on a column of the wrong data type.
It could be that you’ve simply passed the wrong column, or it could be that the column is the correct one, but it’s of the wrong type.
To fix, be sure that the column/expression is of a supported type.
Continue readingSQL Server 2022 introduced the GREATEST()
function that returns the maximum value from a list of values. You may be thinking, “but there’s already a MAX()
function that returns the maximum value, so why the need for another function that does the same thing?”.
Well here’s the thing – they don’t do the same thing. They’re actually quite different functions, used in different scenarios.
If you’re wondering what the difference is between the MAX()
and GREATEST()
functions, read on to find out.
The SQL EXISTS
predicate is used to specify a test for a non-empty set. It returns TRUE
or FALSE
, depending on the outcome of the test.
When we incorporate the EXISTS
predicate operator into our SQL queries, we specify a subquery to test for the existence of rows. If there are any rows, then the subquery is TRUE
. If there are no rows, then the subquery is FALSE
.
If you’re getting an error that reads “The function ‘FIRST_VALUE’ must have an OVER clause” in SQL Server, it’s probably because you’re calling the FIRST_VALUE()
function without an OVER
clause.
The FIRST_VALUE()
function requires an OVER
clause (and that clause must have an ORDER BY
clause).
To fix this issue, be sure to include an OVER
clause when calling the FIRST_VALUE()
function.