Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansi SQL type casting

Is it allowed to cast types in ANSI SQL like in postgres for example:

SELECT SUM( CAST(qnty AS int) - CAST(reserve AS int) )  AS sum
...

qnty and reserve are character columns.

like image 567
Mikhail.Mamaev Avatar asked Oct 07 '09 07:10

Mikhail.Mamaev


People also ask

Is CAST ANSI SQL?

CAST is an ANSI Standard and is supported on SQL Server, MySQL, ORACLE, and others. CAST limits formatting to enable data conversions. CONVERT on the other hand, can be used for formatting date/time, and money data types. CAST has a simple syntax.

What is ANSI format in SQL?

The ANSI SQL standards specify qualifiers and formats for character representations of DATETIME and INTERVAL values. The standard qualifier for a DATETIME value is YEAR TO SECOND, and the standard format is as follows: YYYY-MM-DD HH:MM:SS.

Can you type CAST in SQL?

You can cast to many SQL Server types such as binary , char , varchar , date , datetime , time , decimal , bigint , and float .

What is SQL casting?

SQL Server CAST() Function The CAST() function converts a value (of any type) into a specified datatype. Tip: Also look at the CONVERT() function.


1 Answers

The CAST expression was added in SQL-92. You can see it for example in this draft.

like image 187
Lukáš Lalinský Avatar answered Sep 20 '22 10:09

Lukáš Lalinský