vendredi 1 juillet 2016

SQL Setting Constraints In where clause, not sure what to do

I have another question in regards to constraints in the where clause. Here is my code:

use db.random123
go
create view dbo.increasebasedonvar
as
select *
from dbo.incbasedondate as ibd
where ibd.[avg rent var] < 30 and 
    ([avg rent var] between 15 and 30 and datediff(month,ibd.leasedate, '2016-09-01') > 24)
go

My goal here is to exclude records where the [avg rent var] is >= 30 and exclude a subset of records if the [avg rent var] is between (inclusive) 15 and 30 and the time between the 'leasedate' and a future date is less than 24 months. Then I would like to return all of the remaining records that are not excluded by these parameters.

Unfortunately I am not completely sure how to achieve this I tried putting together an if statement but that didn't seem to work appropriately. Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire