At the company I work for date and time values have always been stored separately in integer fields, so for example 8:30 this morning would be stored like this:
- date of 20091116 and
- time of 83000 (no leading zeros as it is an integer field)
Whereas the time as I type this the time would be stored like this
- date 20091116
- time 133740
Unfortunately if i would like add a BETWEEN to the WHERE clause of a query it introduces a slight complication.
Currently the system I work on is using a query something like this:
declare @minDate int, @minTime int, @maxDate int, @maxTime int
select @minDate = 20091102
select @minTime = 64841
select @maxDate = 20091105
select @maxTime = 102227
SELECT *
FROM transactions
WHERE
(
(
txnDate = @minDate AND
txnTime >= @minTime
) OR
txnDate > @minDate
) AND
(
(
txnDate = @maxDate AND
txnTime <= @maxTime
) OR
txnDate < @maxDate
)
Bearing in mind that I can't change the design of the database...
Is there a better way to do this?