In addition to Solution 1 - why are you converting column
- that column should be of type
. . . always use the right data type for the job. . . It can have a significant impact on efficiency, performance, storage and further database development.
Change your table schema to make
a Date and your query becomes
Select * from T_report where date >= @startdate and created_date <= @enddate
function calls out of the WHERE clause will make a big difference to the speed.
If you already have
declared as a DateTime
then instead of casting/converting the column in the WHERE clause, get clever with your local variables i.e.
set @startdate ='2020-05-01'
Select * from T_report where created_date >=@startdate
One last final note - it's good practice to list the columns you want in your query rather than using
- it stops you getting caught out if the schema changes down the line