SELECT DISTINCT
g.crm_group_object_id as g_crm_group_object_id
, g.name as g_name
FROM
crmdb.dbo.tblA as dp
inner join crmdb.dbo.tblB as cd
on (
dp.crm_contract_detail_id = cd.crm_contract_detail_object_id
)
INNER JOIN tblC as ct
ON (
ct.crm_contract_object_id = cd.crm_contract_object_id
)
inner join crmdb.dbo.tblD as p
on p.crm_product_object_id = dp.crm_product_object_id
inner join tblE as l
on (
l.crm_license_object_id = dp.crm_license_object_id
and keys.dbo.get_mtn_flag_from_entry_pld( l.key_keyno
, p.key_product
, getdate()
, dp.end_date
, dp.data1_mtn_paid_until
, ct.contract_type
, cd.contract_detail_type
, p.product_code
, dp.data1_mtn
, dp.mtn_override
) = 1
)
inner join crmdb.dbo.tblF as cl
on cd.crm_contract_object_id = cl.crm_contract_object_id
inner join crmdb.dbo.tblG as c
on c.crm_company_object_id = cl.crm_company_object_id
inner join tblH as g
on (
c.crm_group_object_id = c.crm_group_object_id
and g.noclientlist = 0
and g.crm_group_object_id_merge = 0
and len(g.name ) > 0
and g.status in ('Entered', 'Active')
and c.status in ('Entered', 'Active')
)
ORDER BY
g.name
|