I have a requirement wherein I have to query a database for the following condition.
Database [Report Pull] has let us say 2 columns
CustomerID ReportDt
I have have to find all the customers who have not have a record in last 30 days but have a record exactly (today - 30 ) among other conditions.
Select Condition on [Report Pull] PR
and cast(PR.ReportDt as Date) = cast(getdate()-30 as date)
and not exists (
select PR2.*
from [Report Pull] PR2
where 1=1
and cast(PR2.ReportDt as Date) > cast(getdate()-30 as date)
and PR2.CustomerId = PR.CustomerId
)
Now i want to pull customers such that
cast(getdate()-30 as date) is mod30 = 0
AND at the same time
cast(PR2.ReportDt as Date) > cast(getdate()-30 as date)
Next
cast(getdate()-60 as date) is mod30 = 0
AND at the same time
cast(PR2.ReportDt as Date) > cast(getdate()-60 as date)
that is no report pulled in last 60 days
and so on for every 30 days. This is because the db can have multiple records of report pull. I know it is a bit confusing, but please help me. :)
Please note we cannot declare any variable in SQL. The DB is Salesforce Marketing CLoud aka ExactTarget