我正在尝试在 sql 中编写 if..else 条件如果它们是 companyID 中的 companyID 为 NULL,我想从“Company”表中获取公司名称打印“N/A”con 有人帮助我
SELECT [contactID]
,[customerID]
,(SELECT Label.labelContactType FROM Label WHERE Label.labelContactTypeID = Customer_Contacts.labelContactTypeID)AS Type
,[contactDetails]
,[status]
,[notes]
,CASE WHEN [Customer_Contacts].companyID = NULL THEN 'N/A'
WHEN [Customer_Contacts].companyID <> NULL THEN (SELECT [companyName]
FROM [TaskManagementSystem_DB].[dbo].[Company] WHERE [Company].companyID = [Customer_Contacts].companyID)
END AS Company
FROM [TaskManagementSystem_DB].[dbo].[Customer_Contacts]
WHERE customerID = 24