D
D
des1roer2015-12-03 13:49:18
SQL
des1roer, 2015-12-03 13:49:18

MS SQL select by datetime?

I can't understand the logic. I'm tinkering with someone else's code. there skl request of the form

select * from
db
where DATE_IZMER>='01.11.2015'
 and DATE_IZMER<='30.11.2015'

I try to execute in the manager I get
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

cast to DATE_IZMER>=cast('2015-11-01' as datetime) no data at all
getdate casts 03.12.2015 15:04:59

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Aleksey Ratnikov, 2015-12-03
@mahoho

Write in the format Ymd: 20151112, this is a locale-independent format, it will always work.

D
Dmitry Kovalsky, 2015-12-03
@dmitryKovalskiy

If you just need to see the result of the query - try writing the dates in the format 'yyyy-MM-dd'

F
Fr0stDev1, 2015-12-03
@Fr0stDev1

This should work.
Writing in the manager at the beginning of the session, I don’t know why, it resets after a restart for me.

M
Max, 2015-12-03
@MaxDukov

tryDATE_IZMER>='01.11.2015 00:00:00.000'

A
Artyom Tokarevsky, 2015-12-03
@artemt

If the query is written to quickly look, it is more visual to use the format '12 december 2015', '1 november 2015', etc. To cast to a date, it is better to write CONVERT instead of CAST with an explicit indication of the date style.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question