Searching data between two dates by ignoring time values

Here is a stored procedure that returns records between from date and to date by ignoring their time values. If the from date , to date are not supplied it returns all the values of the table.


CREATE Procedure [dbo].getAllRecordsIgnoringTimevalues
(
@FromDate VARCHAR(25) =NULL,--indicates that the parameter it is optional
@ToDate VARCHAR(25) =NULL --indicates that the parameter it is optional
)
As
Begin


Select *
From
[dbo].tabletosearch

WHERE
AND (CAST(FLOOR(CAST( fromdate AS float)) AS datetime) >= convert(datetime,@FromDate)OR ISNULL(convert(datetime,@FromDate),'')='')
AND (CAST(FLOOR(CAST( todate AS float)) AS datetime) <= convert(datetime,@ToDate) OR ISNULL(convert(datetime,@ToDate),'')='')

END


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: