以下select语句可以正常工作。
SELECT *
FROM [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST] A
WHERE EXISTS (SELECT 1
FROM [BillingReferenceData].[dbo].[CLIMapping] B
WHERE A.CustomerCLI = B.CLI AND A.CustomerCLI = '84422881')
但是,当我将它包装在CASE语句中时,如下所示
UPDATE [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST]
SET [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST].[CustomerCLI] =
CASE WHEN
SELECT *
FROM [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST] A
WHERE EXISTS (SELECT 1
FROM [BillingReferenceData].[dbo].[CLIMapping] B
WHERE A.CustomerCLI = B.CLI AND A.CustomerCLI = '84422881'))>1
THEN 'X' ELSE 'Y' END
失败并出现以下错误
“当EXISTS未引入子查询时,只能在选择列表中指定一个表达式”
答案 0 :(得分:0)
使用“top 1”
UPDATE [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST]
SET [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST].[CustomerCLI] =
CASE WHEN
SELECT top 1 *
FROM [VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST] A
WHERE EXISTS (SELECT 1
FROM [BillingReferenceData].[dbo].[CLIMapping] B
WHERE A.CustomerCLI = B.CLI AND A.CustomerCLI = '84422881'))>1
THEN 'X' ELSE 'Y' END
答案 1 :(得分:0)
您正试图在CustomerCLI
表中找到[BillingReferenceData].[dbo].[CLIMapping]
号码,并希望在X
表格中使用Y
或[VoiceflexBilling].[dbo].[FEBU17_OWH07579_Calls - TEST]
值进行更新?
您需要在SELECT COUNT(1)
声明中使用CASE
。