I am creating the new variable Subsector
, which should contain the names of all the parties, divided by a dash. All combinations are possible, as each option can either be 0 or 1. So I can have in the Subsector
for Brokers / Custodian alone the combos below ( and that is also how Subsector
should look like in the end:
Of course I can continue writing When
clauses for all possible combos. I am just wondering, is there something more clever and elegant? Because I know, in SAS you can just write this as:
else Subsector=catx(' - ',Broker_Custodian,CrowdFunding_provider,Derivative_Issuer,DIMS_provider ...);
I thought that CONCAT was the equivalent in SQL. But in this case it just adds all the options into one line. It does not calculate, which ones are 0 or 1. Any ideas?
SELECT
* ,
CASE
WHEN (('Broker_Custodian' ='0' )
AND ('CrowdFunding_provider' ='0' )
AND ('Derivative_Issuer' ='0' )
AND ('DIMS_provider' ='0' )
AND ('Financial_Adviser' ='0' )
AND ('Fund_Manager' ='0' )
AND ('Issuer_of_Securities' ='0' )
AND ('Peer_2_Peer' ='0' )
AND ('Broker_Custodian' ='0' )
AND ('Other_Sector' ='0' )
AND ('Trustee_Licensed_supervisor') ='0' )
THEN 'None' ELSE
CONCAT(' - ','Brokers / Custodians', 'Derivatives issuer' , 'DIMS provider' , 'Equity crowdfunding services',
'Financial adviser', 'Fund manager' , 'Issuer_Of_Securities', 'Peer-to-peer lending provider' ,
'Trustee corporation / Licensed supervisor' ,'Other') END AS Subsector FROM #TEST