snippetsqlMinor
How do I list available casts in SQL Server?
Viewed 0 times
availablesqlcastshowserverlist
Problem
In PostgreSQL, there is a command,
To lists the possible
Is there any command like that in SQL Server? How can I find what I can
\dC+ I can use in psql \dC+,\dC[+] [PATTERN] list castsTo 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.
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.
Context
StackExchange Database Administrators Q#212186, answer score: 6
Revisions (0)
No revisions yet.