У меня есть таблица «CustomerAccount» со следующими полями:
- AccountNumber
- AmountDue
- CompanyName
- Cust_FirstName
- Cust_LastName
- Адрес
Я пытаюсь получить простой отчет, но получаю сообщение об ошибке. Я не могу понять, что не так.
Мой код:
SELECT AccountNumber
,AmountDue
--,ISNULL(Cust_LastName, '') + ', ' + ISNULL(Cust_FirstName, '') CustomerName
,CASE WHEN ISNULL(CompanyName, '') = ''
THEN Cust_LastName + ', ' + Cust_FirstName
ELSE CompanyName
END CustomerName
-- Above: This is the line where it gives an error.
-- If there is no Company Name then give the Last and First name of the customer.
,CASE WHEN ISNULL(CompanyName, '') = ''
THEN ''
ELSE Cust_FirstName + ' ' + Cust_LastName
END Attn_To
-- Above: If there IS a Company Name then give the First and Last name of the customer.
,[Address]
FROM CustomerAccount
Сообщение об ошибке:
Не удалось разрешить конфликт сопоставления для столбца 3 в операторе SELECT.
Что я пробовал:
,CASE WHEN ISNULL(CompanyName, '') = ''
THEN '' --Cust_LastName + ', ' + Cust_FirstName
ELSE CompanyName
END CustomerName
-- This works but only gives a CompanyName when there is one.
-- But does not give me the customer name when there is no CompanyName
Если я попробую только ,ISNULL(Cust_LastName, '') + ', ' + ISNULL(Cust_FirstName, '')
вместо оператора CASE, то это сработает. Я получаю Фамилию, Фамилию клиента.