E
E
Eugene2015-07-01 10:55:25
SQL Server
Eugene, 2015-07-01 10:55:25

Why doesn't MS SQL SERVER 2008 understand the DATE type?

I write constructs like
SET @reportDateStart = CAST('2015-05-01 00:00:00.000' AS DATE)
IF @reportDateСurrent = CAST(GETDATE() AS DATE)
CAST(dateSale AS DATE) = CAST(@reportDateСurrent AS DATE) and so on
I get the error
"Type DATE is not a defined system type"
Version MS SQL Server 2008 R2, that is, the DATE type must be supported. And it worked before. And now, under strange circumstances, it either works, or it doesn’t, I don’t understand what affects it.
As a result, you need to get the date without time in the form 2015-07-01 (yyyy-mm-dd, that is). Through CAST and DATE it is easier and more canonical to do this. If there are other ways, please share. But of course I would like it to be humane through CAST and DATE.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Lastochkin, 2015-07-01
@lasalas

DECLARE @TODAY DATETIME = CAST( CAST(GETDATE() AS INT) AS DATETIME)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question