I am working with T-SQL in SQL Server 2000, and I have a TRANSACTIONS table that has a TRANDATE date column defined as DateTime, among many other columns that are not relevant to this issue ..
The table is populated with transactions spanning many years. I came across a code, a test that confused me. There is a simple SELECT , for example:
SELECT TRANDATE, RECEIPTNUMBER FROM TRANSACTIONS WHERE TRANDATE BETWEEN '12/01/2010' and '12/31/2010' ORDER BY TRANDATE
and do not return two rows of data that, as I know, are in this table.
With the above statement, the last row returning, in order, has TRANDATE of: 2010-12-31 00: 00: 00.000
When I change the instruction as shown below, I get an additional two lines for December 2010, which are in this table:
SELECT TRANDATE, RECEIPTNUMBER FROM TRANSACTIONS WHERE TRANDATE BETWEEN '12/01/2010 00:00:00' and '12/31/2010 23:59:59' ORDER BY TRANDATE
I tried to find out why the BETWEEN statement does not include ALL rows for 24 periods on 12/31/2010 when using the first SELECT above. And why is it necessary for explicit hours to be added to the SELECT , as in the second, modified statement, to make it pull out the correct number of rows?
Is it because of the way TRANDATE is defined as " DATETIME "?
Based on this finding, I think I will have to go through all this old code, because these BETWEEN statements are clogged up in this whole old system, and it looks like it did not pull all the data properly. I just wanted to clarify the situation with some people. Thanks!
tsql between sql-server-2000
ONDEV
source share