I have the following query:
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
I get this error when executing:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
After adding the second where clause in the subquery. What can I do to fix this?
You are selecting three columns values into one variable.
Change
to