Below are seven functions we can use to extract the hours, minutes, seconds, and microseconds from a time value in MySQL.
how to
Fix “WRONGTYPE Operation against a key holding the wrong kind of value” when using ZREM in Redis
If you get an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when using the ZREM command in Redis, it’s because you’re passing a key with the wrong data type.
To fix this issue, make sure that you pass a sorted set to the ZREM command.
2 Ways to Set a Maximum and/or Minimum Value when Creating a Sequence in SQL Server
By default, SQL Server sets its own minimum and maximum values for sequence objects based on the data type of the sequence object. Assuming we don’t set the data type for the sequence, these min/max values are based on the bigint data type (because that’s the default data type for sequence objects in SQL Server).
However, we can also set our own minimum and maximum values for our sequences. We can do this either explicitly (by setting the MAXVALUE and MINVALUE properties) or implicitly (by setting the data type).
Fix “START value (…) cannot be less than MINVALUE (…)” When Creating a Sequence in PostgreSQL
If you’re getting an error that reads something like “START value (0) cannot be less than MINVALUE (1)” in PostgreSQL when you’re trying to create a sequence, it’s because your sequence’s start value is lower than its minimum value, when it should be at least the same or higher.
To fix this issue, be sure that the sequence’s start value is at least the same or greater than the minimum value.
How to Update Multiple Fields in a Redis Hash
In Redis, we can update multiple fields in just the same way that we can update a single field. The HSET command allows us to set one or more fields in a hash.
The ability of the HSET command to update multiple fields was introduced in Redis 4.0.0. Prior to that, we needed to use the (now deprecated) HMSET command if we wanted to add more than one field at once.
Fix Error Msg 6825 “ELEMENTS option is only allowed in RAW, AUTO, and PATH modes of FOR XML” in SQL Server
If you’re getting error msg 6825 that reads “ELEMENTS option is only allowed in RAW, AUTO, and PATH modes of FOR XML“, it’s probably because you’re trying to use the ELEMENTS directive while using EXPLICIT mode of the FOR XML clause.
As the message alludes to, this option is not available when using the EXPLICIT mode (it’s only allowed with the RAW, AUTO, and PATH modes).
However, SQL Server does provide us with an equivalent that provides the same result. When using EXPLICIT mode, we can use the ELEMENT directive instead. We apply this to the column names, instead of the end of the query. We can alternatively use the ELEMENTXSINIL directive to ensure that elements are generated even if the column contains a NULL value.
Fix “Argument ‘AS’ cannot be used in an ALTER SEQUENCE statement.” (Error Msg 11711) in SQL Server
If you’re getting an error that reads “Argument ‘AS’ cannot be used in an ALTER SEQUENCE statement.” in SQL Server, it’s probably because you’re trying to change the data type of a sequence object.
We can’t actually change the data type of a sequence object, so this error is to be expected.
If you need to change the data type of a sequence object, you’ll need to drop the sequence and recreate it with the correct data type.
SQL Server FOR XML Explained
In SQL Server, the FOR XML clause allows us to return the results of a query as an XML document.
When we use this clause, we have various options for how we want to shape the resulting XML document.
Below is an explanation of how the FOR XML clause works, including the basic options we have when using it.
Three ISDATE() Alternatives that Work with DATETIME2 Values in SQL Server
SQL Server’s ISDATE() function checks whether or not an expression is a valid date. However, you may be aware that this function doesn’t work on datetime2 values. On datetime2 values it returns 0, which means it’s not a valid date, even when the value is a valid date.
This is obviously not ideal, because the datetime2 type is a valid date type. Microsoft even recommends that we use datetime2 instead of datetime for our dates, as it aligns with the SQL Standard and it provides more fractional seconds precision.
Anyway, below are three options we can use to check whether a datetime2 value is a valid date.
How to Create Decrementing Sequence Numbers in SQL Server
When we create a sequence in SQL Server, we have the option of making it an incrementing sequence or decrementing.
By “decrementing”, I mean that the sequence decreases instead of increases. For example, if it starts at 100, the next value is 99, and then 98, and so on.
To create a sequence that decrements, all we do is provide a negative value for the INCREMENT BY argument.