Home sql MS SQL Sampling by DateTime

MS SQL Sampling by DateTime

Author

Date

Category

I can not understand the logic. I pick someone else’s code there Silospect the view

select * from
DB
Where Date_izmer & gt; = '01.11.2015'
 and Date_izmer & lt; = '30 11.2015'

Trying 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.

Come to the type date_izmer & gt; = Cast ('2015-11-01' As DateTime) No data at all

getdate gives 03.12.2015 15:04:59


Answer 1, Authority 100%

SQL Server has a total two literal formats dates / time, not tied to locale. This

  • yyyy-mm-ddthh: mm: ss [.mmm]
  • yyyymmdd [hh: mm: ss [.mmm]]

… where in […] – optional part

All other are tied to the current locale (including Yyyy-Mm-DD – it breaks it Set Language German )

i.e. If you really want to explicitly sew a date in SQL, then you should use the yyyymmdd format:

select * from
DB
Where Date_izmer & GT; = '20151101'
 and Date_izmer & lt; = '20151130'
 - If there is time in Date_izmer, then better Date_izmer & lt; '20151201'

Answer 2, Authority 50%

Try to write like this:

select *
From db.
Where Date_izmer & gt; = '2015-11-01' and Date_izmer & lt; = '2015-11-30'

Answer 3

select * from zntf_data2 a where a.zntf_datetime between '20190701' and '20190815' Order by A.ZNTF_DATETIME

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions