Hi All,
this is just to know if the following behavior is expected or a bug of SQL Server 2008 R2.
I have a table test with a columntest_date of type DATE. This table has records with different values oftest_date. When I run the query:
SELECT * FROM [test] WHERE test_date=GETDATE()
I receive 0 results, whereas if I use this one:
SELECT * FROM [test] WHERE test_date=COVERT(DATE,GETDATE())
I see the correct results.
It seems that GETDATE() is not implicitly converted toDATE when necessary. Is this a bug or an expected behavior?
Here the test table and some records:
CREATE TABLE [dbo].[test]( [test_id] [int] IDENTITY(1,1) NOT NULL, [test_date] [date] NOT NULL, CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED ( [test_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO INSERT [test] (test_date) VALUES (GETDATE()); INSERT [test] (test_date) VALUES (GETDATE()); INSERT [test] (test_date) VALUES (GETDATE()); INSERT [test] (test_date) VALUES (DATEADD(DAY,-1,GETDATE())); INSERT [test] (test_date) VALUES (DATEADD(DAY,-1,GETDATE())); INSERT [test] (test_date) VALUES (DATEADD(DAY,-1,GETDATE())); INSERT [test] (test_date) VALUES (DATEADD(DAY,-2,GETDATE())); INSERT [test] (test_date) VALUES (DATEADD(DAY,-2,GETDATE())); INSERT [test] (test_date) VALUES (DATEADD(DAY,-2,GETDATE()));