ITsolutionWizard
asked on
sql query
I have c# aspx.net with ms SQL server and have one question about SQL
assume I have a web form and come with start date and end date. the format is 20181201 and 20181231 and they are an integer.
and I have to run a SQL statement like below.
select top 1 * from transacation_history where deposit_date >= 20181201 and deposit <= 20181231
Or
I should use between statement? but I do not know how to do that.
1. Which one run faster?
2. I will convert it into stored procedure. In this logic, is it best practice in ms sql?
Thanks.
assume I have a web form and come with start date and end date. the format is 20181201 and 20181231 and they are an integer.
and I have to run a SQL statement like below.
select top 1 * from transacation_history where deposit_date >= 20181201 and deposit <= 20181231
Or
I should use between statement? but I do not know how to do that.
1. Which one run faster?
2. I will convert it into stored procedure. In this logic, is it best practice in ms sql?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
just typo sorry.
I have one column in the table
I have one column in the table
Assuming is just typo if you check the query plans for the two statements below you may see that actually between is converted to GTE/LTE
select top 1 * from transacation_history where deposit_date >= 20181201 and deposit_date <= 20181231;
select top 1 * from transacation_history where deposit_date between 20181201 and 20181231;
Just make sure index exists on the deposit_date