sql server - Using CASE with Else in SQL view -
i have view in have figure out correct value of ferpa column using case statement. value should 'y' or 'n' depending on addresstype. however, have addresstypes values our customer not agree want me using following logic:
if addresstype = permanent use value cmn_personsferpa table (this table created) , choose ispermaddressferpa flag. if addresstype = local use value cmn_personsferpa table , choose islocaladdressferpa flag.
if addresstype = outside source or international, etc. check see if user has value = 'y' in columns in cmn_personsferpa table (look @ view below).
the issue can customer asking if can use @cmn_personsid parameter. however, these view being used many applications need figure out way without using @cmn_personsid parameter. how can this?
select per.cmn_personsid, per.fullname name, isferpa = case pal.addresstype when 'permanent' perferpa.ispermaddressferpa when 'local' perferpa.islocaladdressferpa else case when (select 1 dbo.cmn_personsferpa perferpa cmn_personsid = @cmn_personsid , (ispermaddressferpa = 'y' or isacctholdaddressferpa = 'y' or isbillingaddressferpa = 'y' or isbillingaddress2ferpa = 'y' or iscssprofaddressferpa = 'y' or isdiplomaaddressferpa = 'y' or islocaladdressferpa = 'y' or isoutsidesrcaddressferpa = 'y' or istaxinfoaddressferpa = 'y' or istempaddressferpa = 'y' or isunivhousingaddressferpa = 'y' or isworkaddressferpa = 'y')) = 1 'y' else 'n' end end cmn_persons per (nolock) inner join cmb_accounts acc (nolock) on (per.cmn_personsid = acc.entityid , acc.entitytype = 'p') inner join cmn_personsferpa perferpa (nolock) on ( perferpa.cmn_personsid = acc.entityid , acc.entitytype = 'p' ) left outer join cmn_personsaddresseslinks pal (nolock) on (per.cmn_personsid = pal.cmn_personsid , pal.ispreferred = 'y') left outer join cmn_addresses addr (nolock) on (pal.cmn_addressesid = addr.cmn_addressesid)
i able resolve issue replacing @cmn_personsid pal.cmn_personsid.
Comments
Post a Comment