Trying to convert a number to a date in SQL Server can be tricky and may not always work. It all depends on the number and what exactly it is that we’re trying to do. That said, here are some scenarios where we can convert a number to a date value.
Continue readingTag: t-sql
SQL Server FOR XML EXPLICIT Examples
In SQL Server, the FOR XML
clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML
clause at the end of the query will output the results in XML.
When we do this, we have the option of specifying RAW
, AUTO
, EXPLICIT
, or PATH
mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.
Below are examples of using EXPLICIT
mode when generating XML from a SQL query.
SQL Server FOR XML RAW Examples
In SQL Server, the FOR XML
clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML
clause at the end of the query will output the results in XML.
When we do this, we have the option of specifying RAW
, AUTO
, EXPLICIT
, or PATH
mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.
Below are examples of using RAW
mode when generating XML from a SQL query.
SQL Server FOR XML AUTO Examples
In SQL Server, the FOR XML
clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML
clause at the end of the query will output the results in XML.
When we do this, we have the option of specifying RAW
, AUTO
, EXPLICIT
, or PATH
mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.
Below are examples of using AUTO
mode when generating XML from a SQL query.
SQL Server FOR XML PATH Examples
In SQL Server, the FOR XML
clause allows us to return the results of a query as an XML document. Simply by placing the FOR XML
clause at the end of the query will output the results in XML.
When we do this, we have the option of specifying RAW
, AUTO
, EXPLICIT
, or PATH
mode. These modes allow us to shape the resulting XML in different ways, and so the mode we choose will determine how the XML is generated.
Below are examples of using PATH
mode when generating XML from a SQL query.
Binary Styles Supported by CONVERT() in SQL Server
Below is a list of binary styles supported by the CONVERT()
function in SQL Server. These are the styles that can be used as the third argument to indicate how the input value is formatted when converting to binary.
We can use these styles when the input expression is binary(n), char(n), varbinary(n), or varchar(n).
Continue readingXML Styles Supported by CONVERT() in SQL Server
Below is a list of XML styles supported by the CONVERT()
function in SQL Server. These are the styles that can be used as the third argument to indicate how the input value is formatted when converting to XML.
Date & Time Styles Supported by CONVERT() in SQL Server
Below is a list of date & time styles supported by the CONVERT()
function in SQL Server. These are the styles that can be used as the third argument to indicate how the input value is formatted.
Numeric Styles Supported by CONVERT() in SQL Server
Below is a list of numeric styles supported by the CONVERT()
function in SQL Server. These are the styles that can be used as the third argument to indicate how the input value is formatted.
Fix Error Msg 8116 “Argument data type datetime2 is invalid for argument 1 of isdate function” in SQL Server
If you’re getting an error that reads Argument data type datetime2 is invalid for argument 1 of isdate function, it’s because you’re passing a datetime2 value to the ISDATE()
function, but this function doesn’t work with datetime2 values.
To fix this issue, either pass a valid date type or use the work around below to provide similar functionality that works with datetime2 values.
Continue reading