|
Hi, if you want to compare a numeric date with a real date in SQL, you first have to convert the numeric date into a valid character representation for a date and use the scalar function DATE() to convert this string representation into a real date. Valid character representations of a date are 'YYYY-MM-DD', 'MM/DD/YYYY' and 'DD.MM.YYYY'. The additional use of the scalar function DATE() is only necessary if you want to calculate with this date otherwise SQL is smart enough to know this string represents a date. If you use the scalar function date with a numeric value, the numeric value must represent the calculated number of days since '0001-01-01'. You also can do the inverse, convert the real date into a character representation of a date with the scalar function CHAR. After built a string that only contains the digits of this character string and convert this string into a numeric value. In your case converting the current date into a numeric date will result in a better performance, because an access path built over the numeric date field can be used. Example: Select * From MyTable Where MyNumDate = Cast(Replace(Char(Current_Date, ISO), '-', '') as Dec(8, 0)); Birgitta
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.