How do I list available casts in SQL Server?
-
06-01-2021 - |
Question
In PostgreSQL, there is a command, \dC+
I can use in psql \dC+
,
\dC[+] [PATTERN] list casts
To lists the possible CASTS
. This is useful, because I can easily find out what I can use to cast to timestamp
,
\dC+ timestamp
List of casts
Source type | Target type | Function | Implicit? | Description
-----------------------------+-----------------------------+-------------+---------------+-------------
abstime | timestamp without time zone | timestamp | yes |
date | timestamp without time zone | timestamp | yes |
timestamp without time zone | abstime | abstime | in assignment |
timestamp without time zone | date | date | in assignment |
timestamp without time zone | timestamp without time zone | timestamp | yes |
timestamp without time zone | timestamp with time zone | timestamptz | yes |
timestamp without time zone | time without time zone | time | in assignment |
timestamp with time zone | timestamp without time zone | timestamp | in assignment |
Is there any command like that in SQL Server? How can I find what I can CAST
to DateTime2
? Is this documented anywhere?
Solution
The Microsoft Docs page for CAST and CONVERT provides a great matrix of conversions in SQL Server.
The image included in the above page:
As far as I know, there is no built-in mechanism for displaying a list of valid casts.
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange