这种情况何时改为工会?

时间:2013-04-18 08:58:17

标签: sql sql-server-2012 case-expression

我想知道是否可以将CASE when then else更改为union all,或类似的内容。

我希望有可能......

例如

CASE WHEN(C.Salutation = 'Dhr.' OR C.salutation = 'dhr.')
         THEN 'Meneer'+' '+ISNULL(C.middlename+' ','')+C.Lastname
    WHEN(C.Salutation = 'Mw.' OR C.salutation = 'mw.')
         THEN 'Mevrouw'+' '+ISNULL(C.middlename+' ','')+C.Lastname
    ELSE 'Meneer/Mevrouw '+ISNULL(C.middlename+' ','')+ISNULL(C.Lastname,'') END AS 'K5'

我希望你们能帮帮我..

1 个答案:

答案 0 :(得分:0)

嗯,是的,你可以,但它很难看:

SELECT 'Meneer'+' '+ISNULL(C1.middlename+' ','')+C1.Lastname AS 'K5'
FROM table C1
WHERE C1.Salutation = 'Dhr.' OR C1.salutation = 'dhr.'
UNION
SELECT 'Mevrouw'+' '+ISNULL(C2.middlename+' ','')+C2.Lastname
FROM table C2
WHERE C2.Salutation = 'Mw.' OR C2.salutation = 'mw.'
UNION
SELECT 'Meneer/Mevrouw '+ISNULL(C.middlename+' ','')+ISNULL(C.Lastname,'')
FROM table C3
WHERE C3.Salutation != 'Mw.' AND C3.salutation != 'mw.'
AND C3.Salutation != 'Dhr.' AND C3.salutation != 'dhr.'