SQL programming / SQL portability |
Use parameters instead of database-specific date/time literals in SQL.
SELECT COUNT(*) FROM table WHERE date_col = '24/12/2005'
Other database servers do support date/time literals as quoted character strings, but the date/time format specification is quite different. The parameter to specify the date/time format can be a database parameter, an environment variable, or a session option.
DEFINE cnt INTEGER DEFINE adate DATE LET adate = MDY(12,24,2005) SELECT COUNT(*) INTO cnt FROM table WHERE date_col = adate
DEFINE cnt INTEGER DEFINE adate DATE LET adate = MDY(12,24,2005) PREPARE s1 FROM "SELECT COUNT(*) FROM table WHERE date_col = ?" EXECUTE s1 USING adate INTO cnt