Click here to Skip to main content
16,018,805 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,

I am facing a problem when used lessthan or equal codition in a query.

SQL
 StartDate <= CONVERT(datetime, @pi_Date, 101)

@pi_Date = EnteredDate.
when I am using the above condition in where clause of a sql query, I am getting only the records which are lessthan the EnteredDate.

How to get the records for which StartDate is less than or equal to the EnteredDate.

Please help me...

--
Thanks,
Gopi.
Posted
Updated 28-Feb-12 4:36am
v2

if your @PI_Date exists only of a day a month and a year and now time indiciaton, the time indication is set to 0:00:00.000.

you can add ' 23:59:59.999' to the @pi_Date varchar and your problem is gone.
Another option is to add 1 day to @PI_Date
 
Share this answer
 
Comments
Gopi9999 28-Feb-12 10:39am    
Hi, Thanks for answering my question.

Could you please tell me how can I add '23.59.59.999' to @pi_Date.
Herman<T>.Instance 29-Feb-12 9:47am    
set @pi_date = @pi_Date + '23:59:59.999'
Gopi9999 1-Mar-12 14:04pm    
Thanks for your reply...
Hey,

I got the answer for it....

In SQL server 2008 and above, there is a datatype named DATE which gives only date without time... this solved my problem


Happy coding,
Gopi.
 
Share this answer
 
To solve the issue without changing the datatype (i.e., using the DateTime datatype), just do this
1. Add 1 day
2. Subtract 1 second.

SQL
set @date = dateadd(s, -1, dateadd(d, 1, @date))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900