In addition to Solution 1 - why are you converting column
created_date
- that column should be of type
Date
or
DateTime
. . . 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
create_date
a Date and your query becomes
Select * from T_report where date >= @startdate and created_date <= @enddate
Taking the
convert
function calls out of the WHERE clause will make a big difference to the speed.
If you already have
created_date
declared as a Date
Time then instead of casting/converting the column in the WHERE clause, get clever with your local variables i.e.
set @startdate ='2020-05-01'
set @enddate='2020-05-31'
Select * from T_report where created_date >=@startdate
and created_date<@enddate
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