Skip to content

Instantly share code, notes, and snippets.

@johndstein
Last active March 29, 2017 20:52
Show Gist options
  • Save johndstein/679e2e4379a002d9ae08ab9827c465c5 to your computer and use it in GitHub Desktop.
Save johndstein/679e2e4379a002d9ae08ab9827c465c5 to your computer and use it in GitHub Desktop.
Query to check for missing bank account info
select
g.id RE_LEGACY_ID__c,
r.constituent_id,
ree.routingno ChargentOrders__Bank_Routing_Number__c,
ree.accountnumber ChargentOrders__Bank_Account_Number__c,
coalesce(sfc.AccountId, sfa.Id) ChargentOrders__Account__c,
g.constituentbankid RE_BANK_ID__c,
case (select accounttype from constituent_bank where id = g.constituentbankid)
when 0 then 'Checking'
when 1 then 'Savings'
end ChargentOrders__Bank_Account_Type__c,
'a1p36000002F9k0AAC' ChargentOrders__Gateway__c,
'Check' ChargentOrders__Payment_Method__c,
'Recurring' ChargentOrders__Payment_Status__c,
case g.installment_frequency
when 1 then 'Annual'
when 2 then 'Semiannual'
when 3 then 'Quarterly'
when 4 then 'Bimonthly'
when 5 then 'Monthly'
else 'ERROR'
end ChargentOrders__Payment_Frequency__c,
'Unending' ChargentOrders__Payment_Stop__c,
substring(
convert(
varchar,
dbo.query_nexttransactiondate(g.id, g.gift_status), 120),
1, 10)
ChargentOrders__Payment_Start_Date__c,
g.schedule_dayofmonth ChargentOrders__Charge_Date__c
from gift g
join records r on r.id = g.constit_id
left outer join re_reporter..re_eft ree
on ree.constituentid = r.constituent_id
left outer join re_reporter..sf_contact sfc
on sfc.re_legacy_id__c = g.constit_id
left outer join re_reporter..sf_account sfa
on sfa.re_legacy_id__c = g.constit_id
where g.type in (30,33)
and payment_type = 6
and gift_status = 1
and coalesce(sfc.AccountId, sfa.Id) is not null
and (ree.routingno is null or ree.accountnumber is null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment