I am trying to find out how many of my online purchasers ever bought anything and returned it and if they returned again and purchased something. So A buys B and returns B and then comes back and buys C and keeps it. I only want those that come back and buy junk from me.
Heres what I have so far. ExternalRef is the same on a purchases and a rejection. So 1011 would be the purchase reference and then 1011 would be the return reference, hence using it for the join.
SELECT DISTINCT a.accountnumber,a.dateplaced as purchasedate,a.exteranlref as [purchase ref] b.dateplaced as returndate,a.amount as purchase
from Transactions a join Transactions b
ON a.externalref = b.externalref
WHERE
a.Category1 = 'purchase' and
b.Category1 = 'return' and
a.RemoteAddress like '10.5%' and
a.AccountNumber = b.accountNumber and
a.DateSettled between @StartDate and
@EndDate and
b.DateSettled > @StartDate and
a.Operation = 'f' and b.Operation = 'f' and
a.ExternalRef not like '%n%'
Any suggestions would be super duper...Thanks
Heres what I have so far. ExternalRef is the same on a purchases and a rejection. So 1011 would be the purchase reference and then 1011 would be the return reference, hence using it for the join.
SELECT DISTINCT a.accountnumber,a.dateplaced as purchasedate,a.exteranlref as [purchase ref] b.dateplaced as returndate,a.amount as purchase
from Transactions a join Transactions b
ON a.externalref = b.externalref
WHERE
a.Category1 = 'purchase' and
b.Category1 = 'return' and
a.RemoteAddress like '10.5%' and
a.AccountNumber = b.accountNumber and
a.DateSettled between @StartDate and
@EndDate and
b.DateSettled > @StartDate and
a.Operation = 'f' and b.Operation = 'f' and
a.ExternalRef not like '%n%'
Any suggestions would be super duper...Thanks