Here is my first table:
And this is my second table:
I'm trying to create an INSERT query so that any of the columns with a result of 'Y' in the first table will be inserted into the second table, but I'm having trouble with the case statement that inserts different values other than 'Y'.
So in the first table, if one record has 'Y' for slp_c, sw_c and other_c, then in the second table after inserting, Discipline1_c = 'SLP', Discipline2 = 'SW' and Discipline3_c = 'OTH'. How do I write the case statement so that the values insert into the second table correctly?
INSERT INTO [dbo].[tb_cdsa_eligibility] ([uniqueid_c], [Discipline1_c],[Discipline2_c], [Discipline3_c])
SELECT
[uniqueid_c],
-- this one is going into Discipline1
CASE
WHEN [slp_c] = 'Y' THEN 'SLP'
WHEN [ot_c] = 'Y' THEN 'OT'
WHEN [SpecEd_c] = 'Y' THEN 'SE'
WHEN [medical_c] = 'Y' THEN 'MED'
WHEN [pt_c] = 'Y' THEN 'PT'
WHEN [sw_c] = 'Y' THEN 'SW'
WHEN [psych_c] = 'Y' THEN 'PSY'
WHEN [other_c] = 'Y' THEN 'OTH'
ELSE NULL
END,
-- this one is going into Discipline2
CASE
WHEN [slp_c] = 'Y' THEN 'SLP'
WHEN [ot_c] = 'Y' THEN 'OT'
WHEN [SpecEd_c] = 'Y' THEN 'SE'
WHEN [medical_c] = 'Y' THEN 'MED'
WHEN [pt_c] = 'Y' THEN 'PT'
WHEN [sw_c] = 'Y' THEN 'SW'
WHEN [psych_c] = 'Y' THEN 'PSY'
WHEN [other_c] = 'Y' THEN 'OTH'
ELSE NULL
END,
-- this one is going into Discipline3
CASE
WHEN [slp_c] = 'Y' THEN 'SLP'
WHEN [ot_c] = 'Y' THEN 'OT'
WHEN [SpecEd_c] = 'Y' THEN 'SE'
WHEN [medical_c] = 'Y' THEN 'MED'
WHEN [pt_c] = 'Y' THEN 'PT'
WHEN [sw_c] = 'Y' THEN 'SW'
WHEN [psych_c] = 'Y' THEN 'PSY'
WHEN [other_c] = 'Y' THEN 'OTH'
ELSE NULL
END
FROM
[cd].[tb_cdsa_eligibility]

