Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

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.
Avatar of lcohan
lcohan
Flag of Canada image

Are there truly two different columns in the above statement? Or rather the same column and it was just typo?
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
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

just typo sorry.
I have one column in the table