Search code examples
sql-serveroracle-databasedateansi-sql

Uniform SQL Date in Oracle SQL and SQL Server


Like the title indicates, I'm trying to make an uniform query, which has compatible syntax for Oracle SQL and for SQL Server

The current syntax I have is written in Oracle and is:

SELECT * 
FROM TableA
WHERE CREATION_DATE = TO_DATE('12-09-2015', 'DD-MM-YYYY') 

When I try to build this in SQL Server, this doesn't work. The syntax of SQL Server is

SELECT * 
FROM TableA 
WHERE OrderDate='12-09-2015'

But this doesn't work in Oracle SQL...

So what is the uniform way to write this?


Solution

  • Use this for something which works on both:

    CAST('2015-09-14' as date)
    

    The cast is executed only once so has no effect on performance.