I have a table named tblAccount where I have two columns:
- DateCreated
- AccountApprovalDate
DateCreated is the date on which the account is created and AccountApprovalDate is the date on which the account is approved.
I need to create a column named ‘AccountApproval/RejectDate’. Here the Reject Date is a derived value.(i.e).There is a table named tblDeclinedaccounts,When accountId is there in this table then select the DateCRetaed column.
This column can have only approval date or reject date.
When AccountApprovalDate is not null, then the value is same. and when reject date is not null then we need to select Datecreated column.
i wrote the following query:
SELECT AC.Datecreated, 'Approved/Rejected Date' =
CASE
WHEN AC.AccountApprovalDate IS NOT NULL THEN
(SELECT AC.AccountApprovalDate)
WHEN AC.AccountApprovalDate IS NULL THEN
(SELECT DA.Datecreated
FROM tblDeclinedAccounts DA
INNER JOIN tblAccount AC ON DA.AccountID = AC.AccountID where DA.AccountID IS NOT NULL)
END
FROM tblAccount AC
I got error on executing:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
This needs to be a sub query.
Why does it need to be a subquery? Just join and use
COALESCE: