Domanda

I need to convert a SQL-statement targeting MSSQL-Server to an equavalent statement for Informix. Unfortunatelly I have neither access to one, nor the other DBMS, so I can't test it.

The MS-SQL-statement is as follows:

SET DATEFORMAT ymd;
SELECT 
     ATTRIBUTE1,
     ATTRIBUTE2,
     TIMESTAMP1,
     TIMESTAMP2,
     ATTRIBUTE3
FROM MY_TABLE
WHERE convert(DATETIME,TIMESTAMP1,104) >= ISNULL(convert(DATETIME,TIMESTAMP2,104), convert(DATETIME,'11.11.1900',104));

Could anyone help me out here please?

Thank you very much in advance.

È stato utile?

Soluzione

At first you do not need to convert datetime into string. Databases very well compares datetime values. Converting to text will make your query slower and it is not clear if it will be able to use indexes.

In Informix datetime (I used type datetime year to second) can be as string literals.

In Informix there is no ISNULL() function, but they have NVL() function.

So I would write WHERE condition as:

WHERE timestamp1 > NVL(timestamp2, '1900-11-11 00:00:00');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top