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.
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.
When using the APPROX_PERCENTILE_DISC()
function in SQL Server, you may get an error that reads “The function ‘APPROX_PERCENTILE_DISC’ must have a WITHIN GROUP clause“. If you get this error, it’s because you omitted the WITHIN GROUP
clause when using the APPROX_PERCENTILE_DISC()
function.
To fix this issue, make sure you include the WITHIN GROUP
clause whenever you use the APPROX_PERCENTILE_DISC()
function.
SQL Server 2022 introduced the IS [NOT] DISTINCT FROM
predicate that compares the equality of two expressions and guarantees a true or false result, even if one or both operands are NULL
.
Normally if we compare two NULL values, they will always be different (although this will depend on your ANSI_NULLS
setting – setting ANSI_NULLS
to OFF
will result in NULL
s being treated as equal). The IS [NOT] DISTINCT FROM
predicate enables us to compare NULL
s as though they’re equal, even when our ANSI_NULLS
setting is set to ON
.
If you’re using SQL Server’s GENERATE_SERIES()
function/relational operator and you’re getting an empty result set, then it could be due to one of the following reasons.
In SQL, we can use the CREATE TABLE IF NOT EXISTS
statement to create a table only if it doesn’t exist. The benefit of doing this is that we won’t get an error if there’s already a table with the same name.
But SQL Server doesn’t support this syntax – at least not in the current version of SQL Server at the time of writing (SQL Server 2022) .
So with SQL Server, we need to do a bit of extra work.
Continue reading