0

我有以下查询:

SELECT QuoteReference,
       CreatedDate,
       StartDate,
       EndDate,
       Operation,
       TableName,
       OccurredAt,
       PerformedBy,
       FieldName,
       OldValue,
       NewValue,
       Quotes.CreatedByID,
       CompletedDate,
       EmailAddress = (SELECT ContactDetails.EmailAddress,
                              QuoteReference,
                              ContactDetails.MobilePhoneNumber
                       FROM   ContactDetails,
                              Quotes,
                              QuoteCustomers
                       WHERE  ContactDetails.ID = Quotes.ID
                              AND QuoteCustomers.QuoteID = ContactDetails.ID)
FROM   Quotes
       JOIN Audit
         ON Quotes.ID = Audit.RowId
WHERE  Quotes.CreatedDate BETWEEN '20100401' AND '20120830'
       AND PaymentReference IS NOT NULL
       AND Audit.OccurredAt > Quotes.CompletedDate
       AND Quotes.EmailAddress < > NULL
       AND TableName = 'Quotes'
       AND Quotes.PolicyReference = NULL
       AND Quotes.CreatedByID < > 2 
ORDER BY  Audit.OccurredAt desc

执行时出现此错误:

当不使用 EXISTS 引入子查询时,选择列表中只能指定一个表达式。

在子查询中添加第二个 where 子句后。我能做些什么来解决这个问题?

4

2 回答 2

0

您正在将三列值选择到一个变量中。

改变

EmailAddress = (SELECT EmailAddress,
                          QuoteReference,
                          ContactDetails.MobilePhoneNumber
                   FROM   ContactDetails,
                          Quotes,
                          QuoteCustomers
                   WHERE  ContactDetails.ID = Quotes.ID
                          AND QuoteCustomers.QuoteID = ContactDetails.ID)

EmailAddress = (SELECT EmailAddress
                   FROM   ContactDetails,
                          Quotes,
                          QuoteCustomers
                   WHERE  ContactDetails.ID = Quotes.ID
                          AND QuoteCustomers.QuoteID = ContactDetails.ID)
于 2012-12-17T11:51:28.653 回答
0

您的子查询必须返回 ONE 行和 ONE 列,因此它应该如下所示:

   EmailAddress = (SELECT TOP 1 ContactDetails.EmailAddress
                   FROM   ContactDetails,
                          Quotes,
                          QuoteCustomers
                   WHERE  ContactDetails.ID = Quotes.ID
                          AND QuoteCustomers.QuoteID = ContactDetails.ID)
于 2012-12-17T11:52:46.703 回答