I have two tables one tables content some value like ID, KMS year, From Date, To date where value in each column is like this
1, 2018-2019, 01-11-2018, 31-10-2019
And other table I am getting a transaction date value. Now according to transaction date KMS year need to define if transaction date range within 1-11-2018 to 31-10-2019 then KMS year will be 2018-2019.
Please help me with this.
CodePudding user response:
You can use 'IF' statement for your query. example below,
If 'TransactionDate' between '1-11-2018' and '31-10-2019' begin select * from 'any Table Name' end
CodePudding user response:
You can have two simple ways:
- Using IF/ELSE
IF (TransactionDate BETWEEN DateFrom AND DateTo)
SELECT...
- Using AND in WHERE statement
SELECT * FROM TableName WHERE TransactionDate BETWEEN DateFrom AND DateTo
I prefer Using AND in WHERE statement but you can use any of these as per your scenario.
