Using a function on a column will mean SQL Server can only do an index scan
rather than a seek which is less efficient.
Try and do stuff like this up front....
SELECT *
FROM order_tbl
WHERE order_date BETWEEN CAST( CONVERT( varchar(20), GETDATE(), 106 ) + '
00:00:00.000' AS datetime )
AND CAST( CONVERT( varchar(20),
GETDATE(), 106 ) + ' 23:59:59.999' AS datetime )
--
Tony Rogerson SQL Server MVP
Independant Consultant
Torver Computer Consultants Ltd
www.sql-server.co.uk [UK Independent SQL Server User Group; FAQ; KBase
etc..]
> No. That will return everything with order dates of 7/25 or 7/26. You
> can get only a single date this way. There are other ways, as well,
> using CONVERT(), and if efficiency is an issue, you might look up
> CONVERT() in Books Online and see what you can do with it.
> Steve Kass
> Drew University
> select * from order_tbl
> > I want all rows that have a date column set to a particular day (give
> > me all rows with date column of '7/25/01'). The dates come in from
> > the users in the format 'mm/dd/yy'.
> > I did somthing like this:
> > select * from order_tbl
> > where order_date between '7/25/01' and dateadd(day, 1,'7/25/01')
> > Is this the best way to do this?
> > Thanks,
> > Jack