Hey all,
I have this table i'm trying to query that contains customer paperwork requirements. Our invoice workflow automatically sends out invoices and other paperwork by e-mail based on the data from this table called BillDocTypes. The table consists of columns like CompanyID, docType , docRequired, docAttach.
Here's a small data sample to give you an idea:
CompanyID | docType | docRequired | docAttach
Company12 POD Y Y
company12 BOL N Y
company12 ACC N Y
company12 INV N Y
company34 POD Y Y
company34 BOL N Y
company34 ACC N Y
company34 INV N Y
company56 POD Y Y
company56 BOL N Y
company56 ACC N Y
company 56 INV N Y
I'm trying to select a list of companies that DON'T have the above details concerning the docRequired and docAttach values, but i need to check the docRequired and docAttach value for each docType.
I wrote this so far, but it's returning 1 row for each doctype as NULL, i want to only have 1 record per company ID:
select DISTINCT cmp_id, case when bdt_doctype='POD' then bdt_inv_attach END as 'POD Attach',
case when bdt_doctype='ACC' then bdt_inv_attach END as 'ACC Attach',
case when bdt_doctype='CNF' then bdt_inv_attach END as 'CNF Attach',
case when bdt_doctype='LUMPER' then bdt_inv_attach END as 'LUMPER Attach',
case when bdt_doctype='POD' then bdt_inv_required END as 'POD Required',
case when bdt_doctype='ACC' then bdt_inv_required END as 'ACC Required',
case when bdt_doctype='CNF' then bdt_inv_required END as 'CNF Required',
case when bdt_doctype='LUMPER' then bdt_inv_required END as 'LUMPER Required'
from billdoctypes
order by cmp_id asc