Greetings All,
I have an existing query that I needed to add two columns to. I did that but now my dilemma is to have the query NOT return NULL values in a particular column (pd.premium_amount). I tried adding WHERE pd.premium_amount IS NOT NULL and that did not do the trick. I was thinking about trying to use CASE statement but didn't really see that as being an option. Below is my code. Any help would be greatly appreciated. Thank you all and have a great rest of your day!
-Chris
USE [AmLink_DW]
DECLARE @Bil_Grps TABLE (bil_grp_id int, bil_grp_sname varchar(50))
INSERT INTO @Bil_Grps (bil_grp_id, bil_grp_sname)
SELECT *
FROM (
VALUES
(1,'NPRIT'),
(2,'BCBS'),
(4,'LGA'),
(5,'HSM'),
(11,'HSM TPA'),
(13,'IHP'),
(15,'LM'),
(17,'SGA'),
(18,'CCSA')) AS vtable
([bill_group_id],[bill_group_short_name])
SELECT DISTINCT pd.premium_detail_id
,d.Account_build_id
,Bill_group_id
,account_name
,d.group_id
,group_sub_id
,addr.state_cd AS [Group State] --newly added column
,plan_code
,subscriber_first_name
,subscriber_last_name
,resident_state
,CONVERT(VARCHAR(10),d.effective_date,101) AS effective_date
,hic_number
,social_security_number
,CASE WHEN appe.plan_id IN (2238,2239,2240,2241,2242,2244,2246,2247,2248,2249,2250,2251,2565,2566)
THEN SUM(pd.premium_amount)
--WHEN (pd.premium_amount) IS NULL THEN 0
--ELSE (pd.premium_amount)
END AS [Fidelity Premium] --newly added column
,net_pdp_premium
,net_enhanced_premium
,net_self_funded
,total_billed_premium
,pdp_cms_capitation_with_lis
,enhanced_cms_capitation_rate
,lis_offset
,total_pdp_premium
,total_enhanced_premium
,CASE WHEN COALESCE(adjustment_apply_month, '1/1/1900') < '1/1/2000'
THEN ''
ELSE CONVERT(VARCHAR(10),adjustment_apply_month ,101)
END AS adjustment_apply_month
,adjustment_code
,CONVERT(VARCHAR(10),invoice_month,101) AS invoice_month
,lives_pdp
,lives_enhanced
,commission_plan_id
,pdp_fees_and_commissions
,enhanced_fees_and_commissions
,aggregate_coverage_fee
,ISNULL(CONVERT(VARCHAR(20),late_enrollment_penalty),'') as late_enrollment_penalty
,d.Subscriber_id
,CONVERT(VARCHAR(10),Report_month,101) AS Report_month
,appe.plan_id
,appe.plan_election_name
FROM AMLINK_GB.AmLink_GB.dbo.algb_premium_detail pd
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_subscriber_plan_election spe ON spe.subscriber_plan_election_id = pd.subscriber_plan_election_id
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_account_group_plan_election agpe ON agpe.group_plan_election_id = spe.group_plan_election_id
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_account_product_plan_election appe ON appe.account_product_plan_election_id = agpe.account_product_plan_election_id
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_plan p ON p.plan_id = appe.plan_id
INNER JOIN DW_GB_STERLING_PART_D d ON d.commission_plan_id = appe.carrier_plan_id AND pd.Subscriber_id = d.Subscriber_id
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_subscriber s ON s.subscriber_id = d.Subscriber_id AND s.[enabled] = 1
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_account_group ag ON ag.account_group_id = s.account_group_id AND ag.enabled = 1
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_group_address ga ON ga.group_id = ag.group_id AND ga.enabled = 1
INNER JOIN AMLINK_GB.AmLink_GB.dbo.algb_address addr ON addr.address_id = ga.address_id AND addr.enabled = 1
WHERE 1 = 1
AND pd.premium_detail_date = '08/20/2015'
AND d.Report_month = '08/20/2015'
AND d.social_security_number <> '258-30-0237'
AND pd.premium_amount IS NOT NULL --tried this but didn't change the number of results
GROUP BY pd.premium_detail_id
,d.Account_build_id
,Bill_group_id
,account_name
,d.group_id
,group_sub_id
,addr.state_cd
,plan_code
,subscriber_first_name
,subscriber_last_name
,resident_state
,CONVERT(VARCHAR(10),d.effective_date,101)
,hic_number
,social_security_number
,net_pdp_premium
,net_enhanced_premium
,net_self_funded
,total_billed_premium
,pdp_cms_capitation_with_lis
,enhanced_cms_capitation_rate
,lis_offset
,total_pdp_premium
,total_enhanced_premium
,CASE WHEN COALESCE(adjustment_apply_month, '1/1/1900') < '1/1/2000'
THEN ''
ELSE CONVERT(VARCHAR(10),adjustment_apply_month ,101)
END
,adjustment_code
,CONVERT(VARCHAR(10),invoice_month,101)
,lives_pdp
,lives_enhanced
,commission_plan_id
,pdp_fees_and_commissions
,enhanced_fees_and_commissions
,aggregate_coverage_fee
,ISNULL(CONVERT(VARCHAR(20),late_enrollment_penalty),'')
,d.Subscriber_id
,CONVERT(VARCHAR(10),Report_month,101)
,appe.plan_id
,appe.plan_election_name
ORDER BY d.Account_build_id, d.subscriber_id
--14864 results being returned