Fix Error 6358 “…is not a valid style number when converting to XML” in SQL Server

If you’re getting error msg 6358 which reads something like 300 is not a valid style number when converting to XML, it’s probably because you’re trying to convert a value to XML, but the style that you’re specifying isn’t supported for conversions to that data type.

It’s not that the conversion can’t happen, it’s just that it can’t happen using the style that you’re specifying.

Continue reading

How to Convert Time Zones in MySQL using the Time Zone Name

When using a function like CONVERT_TZ() to convert between time zones in MySQL, we provide the date/time value, along with the original time zone and the destination time zone (i.e. the time zone that we’re converting to).

One typical way to do this is to use the time zone offset, such as −05:00 to specify the time zone. Another method is to use the time zone name. However, this requires that we have configured named time zones in MySQL.

Continue reading

How CAST() Works in MySQL

In MySQL, CAST() is a built in function that converts a value to another data type. It takes a value of one type and returns a value of the specified type.

You provide the value as an argument when you call the function, as well as the type that you’d like it converted to.

CAST() works similar to CONVERT(), except that the syntax used is slightly different.

Continue reading

Fix Msg 529 “Explicit conversion from data type date to int is not allowed” in SQL Server

If you’re getting SQL Server error Msg 529 that reads Explicit conversion from data type date to int is not allowed, it’s because you’re trying to explicitly convert a date data type to an int data type, which is not allowed in SQL Server.

To fix this issue, try converting the date value to a string first, and then to an integer.

Alternatively, change the destination type to one that’s allowed.

Also, check that you’re trying to convert the correct value. For example, you may have selected the wrong column or variable. In this case, selecting the correct column may fix the problem.

Continue reading

Fix Error 9809 “The style … is not supported for conversions from … to …” in SQL Server

If you’re getting error msg 9809 which reads something like The style … is not supported for conversions from … to … in SQL Server, it’s probably because you’re trying to convert between data types, but the style that you’re specifying isn’t supported for that operation.

It’s not that the conversion can’t happen, it’s just that the style that you’re providing is wrong.

Continue reading

Convert DATE to YYYYMMDD in SQL Server

In SQL Server, we can use functions like CONVERT() or FORMAT() to convert a valid date type into a format like yyyymmdd.

This format adheres to the ISO 8601 standard, which defines dates to be written as yyyymmdd, or when using delimiters, as yyyy-mm-dd.

In SQL Server, the date type expresses dates in the yyyy-mm-dd format, but we can use the following technique to remove the delimiters and express the date as yyyymmdd.

Continue reading

How CONVERT() Works in MySQL

In MySQL, CONVERT() is a built in function that converts a value to another data type. It takes a value of one type and returns a value of the specified type.

We provide the value as an argument when we call the function, as well as the type that we want it converted to.

The CONVERT() function is similar to the CAST() function, which also converts between data types.

Continue reading