I am trying to extract some records from a table, but when I use OR instead of AND, it returns me some records, but not in another case. dates are precisely indicated in the table. What mistake am I making?
select newsid,title,detail,hotnews from view_newsmaster where datefrom>=CONVERT(datetime, '4-22-2010',111) AND dateto<=CONVERT(datetime, '4-22-2010',111)
I think you have your “from” and “to” around the wrong way ...
select newsid,title,detail,hotnews from view_newsmaster where dateto>=CONVERT(datetime, '4-22-2010',111) AND datefrom<=CONVERT(datetime, '4-22-2010',111)
It's hard to say without any model data from your table.
, datefrom , dateto - - , AND -.
datefrom
dateto
AND
dateto CONVERT(datetime, '4-23-2010',111) - , CONVERT(datetime, '4-22-2010',111) - ( ) 22 , .
CONVERT(datetime, '4-23-2010',111)
CONVERT(datetime, '4-22-2010',111)
, 00:00:00, , , .
:
where datefrom>=CONVERT(datetime, '4-22-2010 00:00:00',111) AND dateto<=CONVERT(datetime, '4-22-2010 23:59:59',111)
, BETWEEN:
where fDateField BETWEEN '4-22-2010' AND '4-23-2010'
, - + 1, .. , 23:59:59
AND, ( , ).
When you use OR, you will get dates more than the first, and lower than the second.
OR
These are two different conditions, so it’s reasonable that your results will be different.
What are you trying to achieve? What should return this request?
Source: https://habr.com/ru/post/1742243/More articles:ImageData of an image downloaded externally? - html5Need help installing django-cms - djangoHow to implement the Facebook Like button on your site without using iframe and FBML? - facebookC ++ constant specifier - c ++Does it matter where the Django project exists on the system? - djangoRunning another application from C # - c #Should groupId be unique in a multi-module project? - maven-2Typedef C ++, could not solve its meaning - c ++Python: combining log and wx so that the log flow is redirected to stdout / stderr frame - pythonWCF - passing the current pointer in the header - headerAll Articles