0
我的查詢:的SQL Server 2014不包括行
`SELECT gft_key,
DonorCustomer.cst_ind_full_name_dn as 'Full Name',
DonorCustomer.cst_ixo_title_dn as 'Job Title',
DonorCustomer.cst_org_name_dn as 'Organization',
DonorCustomer.cst_eml_address_dn as 'Email Address',
apl_code as 'Appeal Code',
cmp_code as 'Campaign Code',
prd_name as 'Product Name',
chp_name as 'Chapter Name',
adr_line1,
adr_line2,
adr_city as 'City',
adr_post_code as 'Zip Code',
adr_country as 'Country',
mem_member_type as 'Member Type',
ivd_amount_cp as 'Gift Amount',
fun_code as 'Purpose Code',
gty_type as 'Gift Type',
gft_date as 'Gift Date',
pay_trx_date,
case
when pay_trx_date is null then 'Not Paid' else 'Paid' end as 'Paid?'
FROM
np_gift
JOIN np_gift_type ON gft_gty_key=gty_key
JOIN np_constituent ON gft_dnr_cst_key=dnr_cst_key
JOIN co_customer DonorCustomer ON dnr_cst_key=DonorCustomer.cst_key
JOIN co_customer_x_address ON cst_cxa_key = cxa_key
JOIN co_address ON cxa_adr_key = adr_key
JOIN oe_product ON gft_fpc_prd_key=prd_key
LEFT JOIN np_purpose ON gft_fun_key=fun_key
LEFT JOIN np_campaign ON gft_cmp_key=cmp_key
LEFT JOIN np_appeal ON gft_apl_key=apl_key
JOIN ac_invoice_detail ON gft_ivd_key=ivd_key and ivd_void_flag=0
left outer join ac_payment_detail on pyd_ivd_key=ivd_key
left outer join ac_payment on pyd_pay_key=pay_key
left outer join ac_payment_info on pay_pin_key=pin_key
LEFT JOIN vw_client_uli_member_type ON dnr_cst_key=mem_cst_key
LEFT JOIN co_customer_x_customer ON cxc_cst_key_1 = DonorCustomer.cst_key and (cxc_end_date is null or datediff(dd,getdate(),cxc_end_date) >=0) and cxc_rlt_code='Chapter Member'
LEFT JOIN co_chapter ON cxc_cst_key_2=chp_cst_key
where (pay_trx_date >= '7/1/2017' or pay_trx_date is null)
order by gft_date`
的樣本數據,我得到通過運行查詢:Gift Date pay_trx_date 2013-11-18 2017-07-12 2013-11-29 NULL 2014-12-15 NULL 2017-06-30 NULL 2015-05-01 2017-07-01
通過運行上面的查詢我完成上述結果集。但是,我希望排除禮品日期爲<'7/1/2017'且pay_trx_date爲NULL的行(與我的示例數據中的中間行一樣),但我想保留禮品日期所在的行< =「2017年7月1日」和pay_trx_date不爲NULL(就像在我的樣本數據中的第一個或最後一個行)
它不會運行。我不認爲這是有道理的。我需要排除這些行。 – klima
有人可以通過查看最初的問題來幫忙嗎?謝謝。 – klima