SQL 2008 Query - DATE with <= value

I have a query that I want to run against SQL Reporting Services. I want to use <=DATE. I am having a problem because some falls on the date I am entering it does not show up.

EXAMPLE:  <= '5/11/2015'

My database has a line with this date (2015-05-11 10:12:16.087)  that is not showing up. How do I fi show I can use LESS THEN OR EQUAL TO DATE.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterSenior Software DeveloperCommented:
You need to cast the datetime value to a date like this:

 CAST(myTable.theDate as DATE) <= '5/11/2015'

Open in new window

PortletPaulEE Topic AdvisorCommented:
The best practice method is to use the following:
WHERE ( [date_column] >= '20151105' AND  [date_column] <  '20151106' )
AND ...

Open in new window

In particular note that date literals in the format YYYYMMDD are the safest; don't use ambiguous formats like dd/mm/yyyy or mm/dd/yyyy
The method shown above avoids unnecessary use of functions (saving cpu) and it permits use of indexes if they exist on the date column
I have shown use with parentheses only to indicate that it can sometomes be necessary, particularly if your where clause has OR conditions

for more see:
"Beware of Between"

the best practice with date and time ranges is to avoid BETWEEN and to always use the form:

WHERE col >= '20120101' AND col < '20120201'
This form works with all types and all precisions, regardless of whether the time part is applicable.
Itzik Ben-Gan

Please also note:
sargable: Search ARGument ABLE

Rules of thumb
Avoid applying functions on data values in a sql condition.
Avoid non-sargable predicates and replace them with sargable equivalents.
allenkentAuthor Commented:
Thank you that helps BUT I need this to be written in a visual studio report with the value entered by the user. A hard coded date does not work because I want it to change at the reporting level.

The issue is <= does not give the date they entered. It skips the = portion of the date.

 I could write my prompt as:  
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Russ SuterSenior Software DeveloperCommented:
Then you can cast both arguments as a date value

 CAST([myTable].[myDate] as DATE) <= CAST(@anyDateTimeVariable as DATE)

This will absolutely ignore any time values on either side and compare dates ONLY
PortletPaulEE Topic AdvisorCommented:
Do not use functions on data to suit a filtering predicate, please don't learn that

Declare @datein as date

Select  .....
From .....
Where ( datecol >= @datein AND datecol < dateadd(day,1,@datein )

You don't have to hardcore the date and you can easily add 1 day to that value

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Russ SuterSenior Software DeveloperCommented:
Paul, I don't think that would work very well. It would have some unsatisfactory side effects.

What if @datein was 'Jul 12 2015  7:39PM'?

Your where clause now effectively chooses rows between

Jul 12 2015  7:39PM and Jul 13 2015  7:39PM.
PortletPaulEE Topic AdvisorCommented:
datein is defined as date so it does not carry a time component
PortletPaulEE Topic AdvisorCommented:
the parameter is defined as a date
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.